Question:

Plz correct my queue implemenation of linked list c- program ......?

by  |  earlier

0 LIKES UnLike

include<stdio.h>

#include<conio.h>

#include<alloc.h>

struct node

{

int data;

struct node*next;

} *front,*rear,*temp,*t;

void main()

{

int a,ch;

clrscr();

front=NULL;

rear=NULL;

do

{

int choice;

printf("\n enter 1.INSERT ,2.DELETE,3.DISPALY,4.EXIT");

scanf("%d",&ch);

switch(ch)

{

case 1:

{

printf("\n INSERT OPERATION");

printf("enter the data for the node \t");

scanf("%d",&a);

temp=(struct node*)malloc(sizeof (struct node));

temp->data=a;

temp->next=NULL;

if(front==NULL)

{

front=temp;

rear=temp;

}

else

{

rear->temp=next;

rear=temp;

}

}

break;

case 2:

{

printf("\n DELETION OPERATION");

if(rear==front)

{

printf("\n deletion-not possible");

}

else

{

temp=front;

front=front->next;

temp=t;

free(t);

}

break;

case 3:

{

printf("\n DISPLAY OPERATION |N");

temp=front;

while (temp!=NULL)

{

printf("%d\n",temp->data);

temp=temp->next;

}

}

break;

case 4:

{

exit();

}

break;

default:

{

printf("\n enter the right choice");

}

goto choice;

}

}

}

while (ch<=4);

getch();

}

ERRORs line 37: 'temp' is not a member of 'node'

line 37 : undefined symbol 'next'

line 70:functione exit should have a prototype

line 83:undefined label 'choice'

 Tags:

   Report

2 ANSWERS


  1. For line 83 : remove goto choice. and convert the do-while as

    &quot;while&quot; by just replacing do-keyword with while(ch&lt;=4). In this case give ch=5 in

    &lt;&lt;&lt;void main()

    &lt;&lt;&lt;{

    &lt;&lt;&lt;   int a,ch=5; &lt;--- change like this :

    and then remove &quot;int choice&quot;...

    For line 70 : you need to include stdlib.h and make exit in form exit(int);


  2. This line is not valid:

    rear-&gt;temp=next;

    You may have meant to do rear = temp-&gt;next;

    goto choice;

    This line is trying to jump to a label called choice which doesn&#039;t exist. Actually it&#039;s really not a good idea to use &#039;goto&#039;, use one loop of some sort instead, like a while loop.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.