0% found this document useful (0 votes)
9 views6 pages

Assignment 11

Uploaded by

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

Assignment 11

Uploaded by

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

#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:

Create the BST

enter the data:2

Do you want to add more nodes?(y/n)y

enter the data:3


Do you want to add more nodes?(y/n)y

enter the data:1

Do you want to add more nodes?(y/n)y

enter the data:5

Do you want to add more nodes?(y/n)y

enter the data:3

Duplicate node cant be created!

Do you want to add more nodes?(y/n)y

enter the data:7

Do you want to add more nodes?(y/n)y

enter the data:8

Do you want to add more nodes?(y/n)n

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:1


Inorder with recursion

1 2 3 5 7 8

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:2

Preorder with recursion

2 1 3 5 7 8

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:3

Postorder with recursion

1 8 7 5 3 2

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:4

Enter the search data:5


The node having data 5 found

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:5

enter the data to be deleted:3

Node with right subtree is deleted

1 2 5 7 8

1.inorder with recursion

2.preorder with recursion

3.postorder with recursion

4.search the node

5.Delete node

6.exit

enter your choice:6

You might also like