A
Aris
Hello!
Im trying to implement a queue
using a linked list.
I've made that code
and I expected my Degueue()
function to return the value of the
key of the node I constructed.
But It does not.
In fact it returns "Empty Queue"
what am I doing wrong?
#include <stdlib.h>
#include <stdio.h>
typedef struct Queue * link;
struct Queue
{
link head;
link tail;
link next;
int key;
};
void Enqueue(link Head,link Tail,int data)
{
link ptr=(struct Queue*)malloc(sizeof(struct Queue));
ptr->key=data;
if(Head==0) Head= ptr; else Tail->next=ptr;
Tail=ptr;
}
int Dequeue(link Head,int data)
{
link temp;
if(Head!=0){
data=Head->key;
temp=Head;
Head=Head->next;
}
else
{
printf("Empty Queue\n"); return 0;
}
free(temp);
return data;
}
int main()
{
link head=0;
link tail=0;
Enqueue(head,tail,1);
int x=Dequeue(head,x);
printf("%d\n",x);
return 0;
}
Im trying to implement a queue
using a linked list.
I've made that code
and I expected my Degueue()
function to return the value of the
key of the node I constructed.
But It does not.
In fact it returns "Empty Queue"
what am I doing wrong?
#include <stdlib.h>
#include <stdio.h>
typedef struct Queue * link;
struct Queue
{
link head;
link tail;
link next;
int key;
};
void Enqueue(link Head,link Tail,int data)
{
link ptr=(struct Queue*)malloc(sizeof(struct Queue));
ptr->key=data;
if(Head==0) Head= ptr; else Tail->next=ptr;
Tail=ptr;
}
int Dequeue(link Head,int data)
{
link temp;
if(Head!=0){
data=Head->key;
temp=Head;
Head=Head->next;
}
else
{
printf("Empty Queue\n"); return 0;
}
free(temp);
return data;
}
int main()
{
link head=0;
link tail=0;
Enqueue(head,tail,1);
int x=Dequeue(head,x);
printf("%d\n",x);
return 0;
}