All pastes #620094 Raw Edit

Something

public text v1 · immutable
·published 2007-07-15 06:43 UTC
rendered paste body
void insert(int urgency, LList *pq, customer cust) {
	
	//Initialize a node.
	LLNode *node;
	node=(LLNode *)malloc(sizeof(LLNode));

	//Initialize a customer pointer and a "save" pointer
	LLNode *custp = pq->beg;
	LLNode *custpsave;

	//Put the data in the node.
	node->data=cust;

	
	//Assign the 'linkage'
	//If there is no beginning, make this the beginning.
	if(!(pq->beg)) { 
		pq->beg=node;
	} 
	//Is the first ones urgency less than the call we just input, make the new one the input and move the other one
	else if (pq->beg->data.urgency<(cust.urgency)) {
		pq->beg->prev=node;
		node->next=pq->beg;
		pq->beg=node;
	} else {
		//Traverse the linked list until we find one with a lower urgency than the one we have now
		if(custp->next!=NULL) {
			while(custp->next != NULL) {
				if(cust.urgency > custp->data.urgency) {
					custp->prev=node;
					custp->prev->next=node;
					break;
				}
				if(custp->next !=NULL) {
					custp=custp->next;
				} else {
					custp->next=node;
					custp->next->prev=custp;
					break;
				}
			}
		}
	}
}