0% found this document useful (0 votes)
6 views12 pages

Understanding Queue Data Structures

The document provides an overview of queues as a linear data structure, emphasizing their first-in, first-out (FIFO) nature and key operations such as Enqueue and Dequeue. It includes examples of queue implementations in Java using different data structures like PriorityQueue, LinkedList, and ArrayDeque. Additionally, it illustrates the operations of adding and removing items from a queue.

Uploaded by

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

Understanding Queue Data Structures

The document provides an overview of queues as a linear data structure, emphasizing their first-in, first-out (FIFO) nature and key operations such as Enqueue and Dequeue. It includes examples of queue implementations in Java using different data structures like PriorityQueue, LinkedList, and ArrayDeque. Additionally, it illustrates the operations of adding and removing items from a queue.

Uploaded by

Full name
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Jinan University

Faculty of Science
Dep. Of Computer Science

DATA STRUCTURE
Dr. Rami Safarjalani

2024-2025 Chapter 6: Queue


What is Queue
2

 Queue is a linear data structure used to arrange


operating system processes and to simulate
events in the real world, such as teller lines at
banks…
 A queue is an Abstract Data Type (ADT) where
data enters at the rear of a list and is removed
from the front of the list.
 Queues are an example of a first-in, first-out (FIFO)
data structure
Back Front

Jo Hussam Ahmed Ali Samir Ghadeer


Queue Operations
3

 The two primary operations involving queues


are adding a new item to the queue and
removing an item from the queue.
 The operation for adding a new item is called
Enqueue, and the operation for removing an
item from a queue is called Dequeue.
 The other primary operation (The Peek
method) to perform on a queue is viewing the
beginning item.
Queue data structure
4
Methods of Queue in Java
5

 Enqueue: offer(), add() : Insert an item to the


queue.
 Dequeue: poll(), remove(): Remove an item from
the queue.
 Peek(), element(): Get the top item of the queue,
without removing it.
 size(): Returns the number of items in the queue.
Queue in Java
6
Priority Queue
7

import [Link];
import [Link];
public class PQue {
public static void main(String[] args) {
Queue<String> cars = new PriorityQueue<>();
[Link]("Kia");
[Link]("Volvo");
[Link]("BMW");
[Link]("Front:" + [Link]());
[Link]();
[Link]("Size:" + [Link]());
[Link](cars);
}
}
LinkedList Queue
8

import [Link];
import [Link];
public class LQue {
public static void main(String[] args) {
Queue<String> cars = new LinkedList<>();
[Link]("Kia");
[Link]("Volvo");
[Link]("BMW");
[Link]("1st" + [Link]());
[Link]();
[Link]("Size:" + [Link]());
[Link](cars);
}
}
Array Queue
9

import [Link];
import [Link];
public class AQue {
public static void main(String[] args) {
Queue<String> cars = new ArrayDeque<>();
[Link]("Kia");
[Link]("Volvo");
[Link]("BMW");
[Link](“First" + [Link]());
[Link]();
[Link]("Size:" + [Link]());
[Link](cars);
}
}
EnQueue Operation
10

Back Front
2
New item
X
Ahmed Ali Sami Ghadeer
1
DeQueue operation
11

Back current Front

Ahmad Ali Salim Ghadeer


Print all data of Queue
12

Back current current current current Front

Ali Mohamed Ghadeer Ahmed

You might also like