0% found this document useful (0 votes)
2 views

queue using pointers

The document contains a C program that implements a simple linked list with operations to insert, delete, and traverse nodes. It defines a structure for the nodes and provides functions for each operation, along with a main function to interact with the user. The program handles memory allocation and checks for overflow and underflow conditions.

Uploaded by

vishaltanwar572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

queue using pointers

The document contains a C program that implements a simple linked list with operations to insert, delete, and traverse nodes. It defines a structure for the nodes and provides functions for each operation, along with a main function to interact with the user. The program handles memory allocation and checks for overflow and underflow conditions.

Uploaded by

vishaltanwar572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include<stdio.

h>

#include <stdlib.h>

struct Node {

int info;

struct Node* next;

};

struct Node* Front = NULL;

struct Node* Rear = NULL;

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');
}

You might also like