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

Assignment 10

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment 10

Uploaded by

nehal.arora
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

#include<stdio.

h>

#include<stdlib.h>

struct queue

int data;

struct queue *next;

} *front, *rear, *p, *q;

void enqueue();

void dequeue();

void display();

int main()

int ch;

front = NULL;

rear = NULL;

do{

printf("\n1.Enqueue\n2.Dequeue\n");

printf("Enter your choice: \n");

scanf("%d",&ch);

switch(ch)

case 1:

enqueue();

display();

break;

case 2:

dequeue();
display();

break;

default:

printf("Invalid");

}while(ch<3);

void enqueue()

p = (struct queue*)malloc(sizeof(struct queue));

printf("\nEnter the element you want to add\n");

scanf("%d",&p->data);

p->next = NULL;

if(rear == NULL)

rear = p;

front = p;

else

rear->next = p;

rear = rear->next;

void dequeue()

q = front ;

if(q == NULL)

{
printf("It is Empty!!\n");

else

printf("The elemt to be reomved is %d", q->data);

front = front -> next ;

q -> next = NULL;

free(q);

void display()

q = front;

while(q != NULL)

printf("%d\t",q->data);

q = q->next;

OUTPUT:

PS D:\S.Y\C programming> gcc queue.c

PS D:\S.Y\C programming> ./a.exe

1.Enqueue

2.Dequeue

Enter your choice:

1
Enter the element you want to add

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

2 3

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

2 3 4

1.Enqueue

2.Dequeue

Enter your choice:

Enter the element you want to add

2 3 4 5

1.Enqueue

2.Dequeue

Enter your choice:

1
Enter the element you want to add

2 3 4 5 6

1.Enqueue

2.Dequeue

Enter your choice:

The elemt to be reomved is 23 4 5 6

1.Enqueue

2.Dequeue

Enter your choice:

The elemt to be reomved is 34 5 6

1.Enqueue

2.Dequeue

Enter your choice:

Invalid

You might also like