0% found this document useful (0 votes)
83 views14 pages

Lecture 2.2.3 Operations On Queues

This document discusses queues and basic queue operations. It describes the enqueue and dequeue operations for inserting and removing elements from a queue. The enqueue operation inserts an element at the rear of the queue if space is available. Dequeue removes the element at the front and increments the front pointer. Additional functions like peek(), isfull(), and isempty() are also described to check the front element, check if the queue is full, and check if it is empty. References for further reading on data structures and algorithms are provided at the end.

Uploaded by

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

Lecture 2.2.3 Operations On Queues

This document discusses queues and basic queue operations. It describes the enqueue and dequeue operations for inserting and removing elements from a queue. The enqueue operation inserts an element at the rear of the queue if space is available. Dequeue removes the element at the front and increments the front pointer. Additional functions like peek(), isfull(), and isempty() are also described to check the front element, check if the queue is full, and check if it is empty. References for further reading on data structures and algorithms are provided at the end.

Uploaded by

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

UNIVERSITY INSTITUTE OF ENGINEERING

DEPARTMENT OF COMPUTER SCIENCE AND


ENGG.

Bachelor of Engineering (Computer Science &


Engineering)
DATA STRUCTURES 21CSH-211

Queues DISCOVER . LEARN .


EMPOWER
Basic Operations in Queue
Enqueue Operation

Below are the steps to enqueue (insert) data into a queue


•Check whether the queue is full or not.
•If the queue is full – print the overflow error and exit the program.
•If the queue is not full – increment the rear pointer to point to the next empty space.
•Add the element in the position pointed to by the Rear.
•Return success.
Algorithm for Enqueue Operation

procedure enqueuer (data) 


if queue is full
return overflow
endif
rear ← rear + 1
queue[rear] ← data
return true
end procedure
Dequeue Operation

Below are the steps to perform dequeue operation


•Check whether the queue is full or not.
•If the queue is empty – print the underflow error and exit the program.
•If the queue is not empty – access the data where the front is pointing.
•Increment the front pointer to point to the next available data element.
•Return success.
Algorithm for Dequeue Operation

procedure dequeue 
if queue is empty
return underflow
end if
data = queue[front]
front ← front + 1
return true
end procedure
Algorithm for Dequeue Operation

procedure dequeue 
if queue is empty
return underflow
end if
data = queue[front]
front ← front + 1
return true
end procedure
peek()
This function helps to see the data at the front of the queue. The algorithm of peek()
function is as follows −
Algorithm
begin procedure peek
return queue[front]
end procedure

Example
int peek()
{
return queue[front];
}
isfull()
As we are using single dimension array to implement queue, we just check for the rear
pointer to reach at MAXSIZE to determine that the queue is full. In case we maintain the
queue in a circular linked-list, the algorithm will differ. Algorithm of isfull() function −

Algorithm
begin procedure isfull
if rear equals to MAXSIZE
return true
else
return false
End if
end procedure
Example
bool isfull() {
if(rear == MAXSIZE - 1)
return true;
else
return false;
}
isempty()
Algorithm of isempty() function −

Algorithm
begin procedure isempty
if front is less than MIN OR front is greater than rear
return true
else
return false
endif
end procedure
If the value of front is less than MIN or 0, it tells that the queue is not yet initialized, hence
empty.
Here's the C programming code −
Example
bool isempty() {
if(front < 0 || front > rear)
return true;
else
return false;
}
REFERENCES

• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
• Goodrich, Michael T., Tamassia, Roberto, and Mount, David M., “Data Structures and Algorithms in C++”, Wiley Student
Edition.
• https://www.tutorialspoint.com/data_structures_algorithms/algorithms_basics.htm
• https://www.cs.utexas.edu/users/djimenez/utsa/cs1723/lecture2.html
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
• Lipschutz, Seymour, “Data Structures”, Schaum's Outline Series, Tata McGraw Hill.
• Gilberg/Forouzan,” Data Structure with C ,Cengage Learning.
• Augenstein,Moshe J , Tanenbaum, Aaron M, “Data Structures using C and C++”, Prentice Hall of India

13
THANK
YOU

You might also like