queue using pointers
queue using pointers
h>
#include <stdlib.h>
struct Node {
int info;
};
void Insert() {
struct Node *PTR;
PTR = (struct Node *)malloc(sizeof(struct Node));
if(PTR == NULL)
{ printf("Overflow\n"); }
else {
printf("Enter the value");
scanf("%d",&PTR -> info);
PTR -> next = NULL;
If (Rear == NULL) {
Front = PTR;
Rear = PTR;
}
else {
Rear -> next = PTR;
Rear = PTR;
}
}
}
void Delete() {
if(Front == NULL) {
printf("Underflow\n");
} else {
struct Node *PTR;
PTR = Front;
Front = Front -> next;
printf("%d",PTR -> info);
free(PTR);
}
}
void Traverse() {
struct Node *PTR;
PTR = Front;
while(PTR ->next != NULL) {
printf("\nno = %d ", PTR -> info);
PTR = PTR -> next;
}}
int main()
{
int choice;
char ch;
do {
printf("1.Insert\n");
printf("2.Traverse\n");
printf("3.Delete\n");
printf("Enter your choice:\n");
scanf("%d",&choice);
switch(choice) {
case 1:
Insert();
break;
case 2:
Traverse();
break;
case 3:
Delete();
break;
default:
printf("\nYou have entered a wrong choice.\n");
}
printf("\nDo you want to continue? (Y/n)");
scanf(" %c",&ch);
} while(ch=='Y'||ch=='y');
}