0% found this document useful (0 votes)
44 views7 pages

Algorithms and Data Structures: Queue

1. A queue is a first-in first-out (FIFO) data structure for holding ordered items. Items are added to the rear of the queue and removed from the front. 2. The queue abstract data type (ADT) defines operations for adding items to the queue (enqueue), removing items from the queue (dequeue), checking if the queue is empty, and accessing the front item. 3. Queues can be used to check if a string is a palindrome by adding characters to a queue and checking if the reversed sequence matches the original.

Uploaded by

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

Algorithms and Data Structures: Queue

1. A queue is a first-in first-out (FIFO) data structure for holding ordered items. Items are added to the rear of the queue and removed from the front. 2. The queue abstract data type (ADT) defines operations for adding items to the queue (enqueue), removing items from the queue (dequeue), checking if the queue is empty, and accessing the front item. 3. Queues can be used to check if a string is a palindrome by adding characters to a queue and checking if the reversed sequence matches the original.

Uploaded by

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

Algorithms and Data

Structures
Queue
Definition

a b c d e f
queue

front end

Queue is an ADT that can handle ordered


collection of item in FIFO (First In First Out)
or
into which item is inserted into the end of queue
and removed from other end
Queue
Queue ADT
Queue() remove()

add(obj)
Queue() {
ListNode front;
ListNode end;
Queue
Queue(); // create empty queue
void add(Object obj); // add object to queue
Object remove(); // get & throw top element
isEmpty()
ListNode getFront(); // get top element
getFront() boolean isEmpty(); // check if stack empty
}

Queue
Sample Code
Queue q = new Queue();
q.add(‘a’);
a b c d e f
q.add(‘b’);
q.add(‘c’); queue
q.add(‘d’);
String str = q.getFront(); front end
q.remove();
q.add(‘e’); a
q.add(‘f’);
q.remove();

str

Queue
Checking Palindrome
Palindrome is sequence of character that is the
same if it is read from left to right or
right to left
Procedure:
“c1 c2 c3 c4 c5 c6”
 Given a string
 Reverse character order
using stack c6 c5 c4 c3 c2 c1
 Enter characters into
queue
 Check if the two sequences c1 c2 c3 c4 c5 c6
are the same

Queue
Implementation
 Using Linked-List Iteration
 Using circular array

queue.add(‘g’);
queue queue.add(‘h’);
queue.add(‘i’);
ja b c d e f g h i queue.remove();
queue.remove();
queue.add(‘j’);

front end

Queue
Assignment (19 Oktober 2017)
Make your own code for:
 Implementing queue using Linked-List
 Implementing queue using DoublyLinked-
List
 Checking palindrome
 Implementing queue using circular array
 Implementing priority queue

Queue

You might also like