Monday, 20 December 2010

algorithm to implement Queue operations by using the pointers

Description :


In this program we have to implement the Queue operation by using the pointers. Here they Queue operation are push and pop. Push operation is used to insert the elements into a Queue and pop operation is used to remove the elements in to a Queue.

Algorithm:


Step 1: Start
Step 2: define structure for queue
Step 3: read choice
Step 4: if choice = insert
i) read the element 
ii) create a data structure 
iii) if empty queue then front of queue pinter points to newly created data structure 
iv) otherwise end of the queue points to newly created data structure Step 5: if choice= remove 
i) check if queue is empty . if so, print queue is empty 
ii) otherwise read the element pointed by front of the queue temp pointer points to front of queue 
iii) front of queue points to next element 
iv) free the element pointed by temp pointer 
v) return the element 
vi) print the element 
Step 6: if choice = display
i) check of empty queue if so, print queue empty 
ii) otherwise print the elements from front of the queue until the end of the queue 
step 7: if choice=exit stop


Output:


****IMPLEMENTATION OF QUEUE USING POINTERS****
==============================================
MENU
==============================================
[1] To insert an element 
[2] To remove an element 
[3] To display all the elements 
[4] Exit

Enter your choice:1

Element to be inserted:23


****IMPLEMENTATION OF QUEUE USING POINTERS****
==============================================
MENU
==============================================
[1] To insert an element 
[2] To remove an element 
[3] To display all the elements 
[4] Exit 

Enter your choice:3

Elements present in Queue are: 23


****IMPLEMENTATION OF QUEUE USING POINTERS****
==============================================
MENU
==============================================
[1] To insert an element 
[2] To remove an element 
[3] To display all the elements 
[4] Exit 
Enter your choice:2
23 is removed from the queue





****IMPLEMENTATION OF QUEUE USING POINTERS****
==============================================
MENU
==============================================
[1] To insert an element 
[2] To remove an element 
[3] To display all the elements 
[4] Exit 

Enter your choice:4
Exit

Conclusion : the program is error free


VIVA QUESTIONS: 

1) Define queue ?
Ans: A queue is a linear, sequential list of that are accessed in the oeder first in first out(FIFO).

2) Define circular queues ?
Ans: A queue can also be circular in which case, it is called as a circular queue



No comments:

Post a Comment