Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.btechsmartclass.com. Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle.

Similar presentations


Presentation on theme: "Www.btechsmartclass.com. Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle."— Presentation transcript:

1 www.btechsmartclass.com

2 Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle. Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle. In a Queue always the Insertion operation is done at “rear” and Deletion operation is done at “front”. In a Queue always the Insertion operation is done at “rear” and Deletion operation is done at “front”. In a Queue sequence of elements entered into the queue is same as the sequence of elements leave the queue. In a Queue sequence of elements entered into the queue is same as the sequence of elements leave the queue.

3 Queue Definition Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle. Fields rear – used to store the position of insertion front – used to store the position of deletion size – used to store the size of the queue element – used to store the value to be inserted Functions enQueue(element) – to insert into queue deQueue( ) – to delete from queue display( ) – to display all elements in queue Condition Rear >= size – Queue is full Front == rear – Queue is empty

4 #define size 10 void main() { int Q[size], front = -1, rear = -1,op,element; void enQueue(int); void deQueue(); void display(); printf(“Select your option: ”); printf(“1: Insert\n2: Delete\n3: Display\n”); scanf(“%d”,&op); switch(op) { case 1: printf(“Enter element to be insert: ”); scanf(“%d”,&element); enQueue(element); break; case 2: deQueue(); break; case 3: display(); break; } }

5 f = front r = rear f = r = -1 Q Queue is EMPTY Queue is EMPTY 012345... SIZE-1 When the compiler executes above code it allocates memory as follows….

6 Insertion Q enQueue( int element ) { if( rear != size-1) { rear ++; Q[rear] = element; } } else printf(“Queue is full !!!”); enQueue(10) 0123456789 10 enQueue(20) 20 enQueue(30) 30 enQueue(40) 40

7 Deletion Q deQueue( ) { if( front != rear ) { front ++; printf(“\nElement removed : %d”,Q[front]); } } else printf(“Queue is empty !!!)”; deQueue( ) 0123456789 10203040 deQueue( )

8 Display Q if( front != rear ) { for(int i=front+1; i<=rear, i++) printf(“%d\t”,Q[i]); } } else printf(“Queue is empty !!!”); display( ) 0123456789 10203040 display( ) {


Download ppt "Www.btechsmartclass.com. Introduction Queue is a linear Data Structure in which the operations are performed based on FIFO (First In First Out) principle."

Similar presentations


Ads by Google