QUESTION
QUESTION
Objective:
The objective of this lab is to give some basic concepts about QUEUE data structure.
After completion of the lab students will know:
• How to create data element in queue
• How to delete data element from queue
• How to perform different operations on queue i.e. copying, compression of string
etc.
• Different applications of queue in real life
Preliminaries:
A queue or FIFO (first in, first out) is an abstract data type that serves as a collection of
elements, with two principal operations: enqueue, the process of adding an element to
the collection.(The element is added from the rear side) and dequeue, the process of
removing the first element that was added. (The element is removed from the front
side). It can be implemented by using both array and linked list.
Queue is used when things don’t have to be processed immediately but have to be
Page 1 of 3
processed in First in First out order. This property of Queue makes it also useful in
following kind of scenarios.
Lab Task:
Exercise 1:
Create Queue (Enqueue)
Create queue allocates a new node for the queue. It first initializes the front and rear
pointers to null. If the queue is empty then insert new node in queue and update both
the front and rear pointer with the address of the new node and if queue is not empty
then update the rear pointer with the address of the new node
Exercise 2:
Delete node from Queue (Dequeue)
It begins by checking to make sure there are data in queue. If there are, it takes the
addresses of the data being deleted , adjust the front pointer and remove the allocated
memory space.
Exercise 3:
Print Queue
The print function will print the entire queue data.
Exercise 4:
CopyQueue
Write a program that copies the content one queue to another
Page 2 of 3
Exercise 5:
Compression of string
Write a program that compresses a string by deleting all space characters in the string.
Solve the problem using Queue
Exercise 6:
Stack to Queue Creation
Write a program that creates a Queue from a stack. After creation the top of the stack
will be the front of the queue.
Exercise 7:
Delete all Negative Integer
Write a program that will take a queue of integers and deletes all negative integers
without changing the order of the remaining elements in queue.
Page 3 of 3