
Here's my code.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
#define MAX 10
struct linkedqueue
{
int data;
struct linkedqueue *next;
};
typedef struct linkedqueue *q;
int stat=0;
q insq(q hNode)
{
q temp,cur;
temp=(q)malloc(sizeof(q));
if(stat==MAX)
{
printf("\nQueue_Overflow_Error. Re-run the program.\n");
getch();
return hNode;
}
stat++;
cur=hNode;
printf("\nEnter the value:\n");
scanf("%d",&temp->data);
temp->next=NULL;
if(hNode==NULL)
{
return temp;
}
if(stat==1)
{
cur->next=temp;
return hNode;
}
while(cur->next!=NULL)
cur=cur->next;
cur->next=temp;
return hNode;
}
q delq(q hNode)
{
q cur;
if(stat==0)
{
printf("\nQueue_Underflow_Error.\n");
return hNode;
}
if(stat==1)
{
printf("\nDeleted %d.\n",hNode->data);
free(hNode);
return NULL;
}
printf("\nDeleted %d.\n",hNode->data);
cur=hNode;
hNode=hNode->next;
free(cur);
return hNode;
}
void dispq(q hNode)
{
q cur;
if(stat==0)
{
printf("\nQueue_Empty_Error.\n");
return;
}
cur=hNode;
printf("\nThe queue elements are:\n");
while(cur!=NULL)
{
printf("\n\t%d",cur->data);
cur=cur->next;
}
}
void main()
{
q fNode;
int opt;
fNode=NULL;
system("cls");
while(1)
{
system("cls");
printf("\nQueue counter: %d.\n\n",stat);
printf("\nMenu:\n");
printf("\n\t1. Insert\n\t2. Delete\n\t3. Display\n\t0. Exit\n\n");
printf("\nInput please: ");
scanf("%d",&opt);
switch(opt)
{
case 1: fNode=insq(fNode);
break;
case 2: fNode=delq(fNode);
getch();
break;
case 3: dispq(fNode);
getch();
break;
case 0: exit(100);
default: printf("\nInvalid Input.\n");
getch();
break;
}
}
}
What could be the possible error?

New Topic/Question
Reply



MultiQuote





|