Professional Documents
Culture Documents
Circular 1
Circular 1
PROGRAMS :
1.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node*front = NULL;
struct node *rear = NULL;
void enqueue()
{
struct node *newnode = (struct node*)malloc(sizeof(struct node));
if (newnode == NULL)
printf("MEMORY NOT ALLOCATED \n");
else
{
printf("ENTER ELEMENT ");
scanf_s("%d", &newnode->data);
newnode->next = NULL;
if (front == NULL && rear == NULL)
{
front = rear = newnode;
newnode->next = front;
}
else
{
rear->next = newnode;
newnode->next = front;
rear = newnode;
}
printf("ELEMENT ADDED\n ");
}
}
void dequeue()
{
}
void display()
{
if (front == NULL && rear == NULL)
{
printf("QUEUE IS EMPTY \n");
}
else
{
struct node *temp;
temp = front;
do
{
printf("%d ", temp->data);
temp = temp->next;
} while (temp != front);
}
}
int main()
{
int a = 1, ch;
printf("1:ENQUEUE 2:DEQUEUE 3:PEEK 4:DISPLAY 5:END\n");
do
{
printf("\n ENTER YOUR CHOICE ");
scanf_s("%d", &ch);
switch (ch)
{
case 1:enqueue();break;
case 2:dequeue();break;
case 3:peek();break;
case 4:display();break;
case 5:a = 0;break;
default:printf("WRONG CHOICE \n");break;
}
} while (a != 0);
_getch();
}
Output: