Example #1
0
int enqueue(list* listPtr,int priority,void* data){
	Node* nodePtr = calloc(sizeof(Node),1);
	Node *temp=calloc(sizeof(Node),1);
	Node *temp2=calloc(sizeof(Node),1);
	if(listPtr->length == 0){
		return createFirstNode(nodePtr,listPtr,data,priority);
	}
	else{
		createNode(nodePtr,data,priority);
		temp = listPtr->head;
		if(temp->priority > nodePtr->priority)
			return insertFirst(nodePtr,temp,listPtr);
		while(temp->next!=NULL)
			temp= temp->next;	
		if(temp->priority < nodePtr->priority)
			return insertLast(temp,nodePtr,listPtr);
		temp = listPtr->head;
		while(temp->priority < nodePtr->priority){
			temp2=temp;
			temp=temp->next;
		}
		temp2->next = nodePtr;
		nodePtr->next=temp;
		listPtr->length +=1;
		return 1;	
	};
}
Example #2
0
int main(int argc, char const *argv[])
{
	struct Node* head = createFirstNode(2);
	addNode(head, 3);
	printNode(head);

	return 0;
}