Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PLEASE HELP. QUEUE LINKED LIST :(

thenameyoucanthenameyoucan Posts: 2Member
Please help, this is our final project in data struct.
------------------
Queue is an ordered collection of items from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (called the rear of the queue). It exhibits a first-in/first-out(FIFO behavior. Two basic operations associated with a queue are APPEND or ENQUEUE and SERVE or DEQUEUE.

You are required to write a program to APPEND and SERVE an element from the queue using a dynamic data structure. Please use the declaration below.

[b]struct Node{
int data;
struct node *link;
};
typedef struct Node *QueuePointer;
QueuePointer append(QueuePointer head, QueuePointer tail, int num);
int serve(QueuePointer head, QueuePointer tail);
void display_queue(QueuePointer head, QueuePointer tail);

main()
{
QueuePointer Head = Tail = NULL;
.....
}[/b]
The program must meet the following requirements:
*Menu screen that allows the user to choose the selection to go to different process such as ENQUEUE, DEQUEUE, Display, Exit.

*Once the users choose to proceed to ENQUEUE, the program will prompt the user to enter a data and this data will be added to the queue. Once successfully added, it will display the entire queue.

*When the user chooses to proceed to DEQUEUE, the program will display the data that will be deleted from the queue. Once successfully deleted, it will display the entire queue. If the queue is empty then display an appropriate message.

*The program only terminates once Exit is chosen.


-------------
This is the program that i've made. But there are some errors. Im having a hard time debugging it. Hope someone can help me.

[b]#include
#include
#include

struct list{
int data;
struct node *link;
};
typedef struct Node *QueuePointer;

QueuePointer append(QueuePointer head, QueuePointer tail, int num);
int serve(QueuePointer head, QueuePointer tail);
void display_queue(QueuePointer head, QueuePointer tail);



void main()
{

int opt;
char ch;
QueuePointer head;
QueuePointer tail;
head=tail=NULL;
do
{
clrscr();
printf("
Enter your option to perform in a queue
");
printf("
[A] ENQUEUE
");
printf("
[B] DEQUEUE
");
printf("
[C] Display
");
scanf("%d",&opt);
switch(opt)
{
case 'A':
append(&head,&tail);
break;
case 'B':
serve(&head,&tail);
break;
case 'C':
display_queue(&head,&tail);
break;
}
printf("
Do you wish to continue[y/n]
");
ch=(char)getche();
}while(ch=='Y' || ch=='y');
printf("
Press any key to exit
");
getch();
}

QueuePointer append(QueuePointer head,QueuePointer tail,int num)
{
QueuePointer *newnode;
newnode=(struct node *)malloc(sizeof(struct Node));
newnode->link=NULL;
printf("
Enter the character to push
");
fflush(stdin);
scanf("%c",&(newnode->data));
if(head==NULL && tail==NULL)
{
head=newnode;
tail=newnode;
}
else
{

(tail)->link=newnode;
head=newnode;
}
}

int serve(QueuePointer head,QueuePointer tail)
{
QueuePointer *delnode;
if((head)==NULL && (tail)==NULL)
printf("
Queue is empty to delete any element
");
else
{
delnode=head;
(head)=(head)->link;
free(delnode);
}
}
void display_queue(QueuePointer head)
{
while(head!=NULL)
{
printf(" %c ",head->data);
head=head->link;
}
}





[/b]


Sign In or Register to comment.