I am currently doing a Queue program a using structs and linked lists. Most of it works fine however the menu used to drive it keeps having runtime errors when i try to print the queue.
Am I doing something wrong?
functions
Code:
CTaxi_addTaxi(int TaxiReg)
{
struct node *temp,*r;
temp= (struct node *)malloc(sizeof(struct node));
temp->data=TaxiReg;
r=(struct node *)p;
if (p == NULL)
{
p=temp;
p->next =NULL;
}
else
{
while( r->next != NULL)
r=r->next;
r->next =temp;
r=temp;
r->next=NULL;
}
}
CTaxiDelete(char taxi)
{
struct node *temp, *m;
temp=p;
while(temp!=NULL)
{
if(temp->data==taxi)
{
if(temp==p)
{
p=temp->next;
free(temp);
return;
}
else
{
m->next=temp->next;
free(temp);
return;
}
}
else
{
m=temp;
temp= temp->next;
}
}
}
CTaxi_printQueue(struct node *r)
{
r=p;
if(r==NULL)
{
printf("Taxi Rank is currently empty!");
return;
}
while(r!=NULL)
{
printf(" -> %d ",r->data);
r=r->next;
}
printf("/n");
}
menu
Code:
main()
{
int menuChoice = 0;
p=NULL;
while(menuChoice != 4)
{
printf("1.Add Taxi\n");
printf("2.Delete Taxi\n");
printf("3.Print current taxi queue\n");
printf("4.Exit\n");
printf("Enter a choice from the above menu:");
scanf("%d",&menuChoice);
switch(menuChoice)
{
case 1:
{
int TaxiReg;
printf("Please enter a reg no :\n");
scanf("%d",&TaxiReg);
CTaxi_addTaxi(TaxiReg);
break;
}
case 2:
{
int TaxiReg;
printf("Please enter a reg no to delete :\n");
scanf("%d",&TaxiReg);
CTaxiDelete(TaxiReg);
break;
}
case 3:
{
struct node *n;
printf("The Current taxi queue is:\n");
CTaxi_printQueue(n);
break;
}
case 4:
{
menuChoice =4;
return;
}
}
}
}
Also is there a way to search for a specific node in the list? So if I wanted to find a particular taxi entered by the user it will display it.
Thanks for any help/suggestions given