Iam trying to build a queue data structure that contains Nodes each node have integer value and a pointer to the next node there is something wrong with he deQueue(Queue q); function , it is returning elements like a stack (LIFO) here is my code and the output
deQueue();
int deQueue(Queue* q){
if(q->head)
{
int result;
Node*temp=q->head;
result=temp->value;
q->head=temp->next;
free(temp);
if(q->head==NULL)
q->tail=NULL;
return result;
}
}
enQueue():
void enQueue(Queue* q ,Node* node){
if(isEmpty(q)){
q->head = q->tail = node;
q->head->next = q->tail->next = NULL;
q->size++;
}
else{
q->tail->next = node;
q->tail = node;
q->tail->next = NULL;
q->size++;
}
}
main():
int main()
{
Queue* q = initializerQueue();
Node* n1 = newNode(10);
Node* n2 = newNode(20);
Node* n3 = newNode(30);
Node* n4 = newNode(40);
enQueue(q , n1);
enQueue(q , n2);
enQueue(q , n3);
enQueue(q , n4);
printQueue(q);
printf("\n%d - %d - %d - %d " , deQueue(q) , deQueue(q) , deQueue(q) , deQueue(q));
return 0;
}