Queue Data Structure: Array Implementation and Applications, Lecture notes of Data Structures and Algorithms

A comprehensive overview of the queue data structure, focusing on its implementation using arrays. It explains the basic concepts of queues, including enqueue and dequeue operations, and illustrates these with c++ code examples. The document also covers applications of queues in cpu scheduling and synchronization, offering practical insights into their use in computer science. Exercises are included to reinforce understanding and encourage hands-on learning, making it a valuable resource for students studying data structures and algorithms. This lab document is useful for university students.

Typology: Lecture notes

2022/2023

Available from 11/17/2025

marwan-ahmed-10
marwan-ahmed-10 🇪🇬

6 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Data Structures | Level 2 | Lab 4
1 | P a g e
Queue Using Array
1- What is the Queue?
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is
open at both its ends. One end is always used to insert data (enqueue) and the other is used
to remove data (dequeue). Queue follows First-In-First-Out methodology (FIFO), i.e., the data
item stored first will be accessed first.
1- Applications of Queue data Structure:
- Queue is useful in CPU scheduling, Disk Scheduling.
- Queue is used for synchronization. Examples: IO Buffers, pipes, file IO, etc.
Queue Using Dynamic Array Code:
#include <iostream>
using namespace std;
int front,rear;
int size;
int *Queue;
bool isFull()
{
if (rear==size-1)
return true;
else
return false;
}
bool isEmpty()
{
if (front==-1 || front > rear)
return true;
else
return false;
}
void enqueue(int item)
{
if (isFull())
cout<<"Queue Overflow \n";
else
pf3

Partial preview of the text

Download Queue Data Structure: Array Implementation and Applications and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Queue Using Array

1- What is the Queue?

Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is

open at both its ends. One end is always used to insert data (enqueue) and the other is used

to remove data (dequeue). Queue follows First-In-First-Out methodology (FIFO), i.e., the data

item stored first will be accessed first.

1 - Applications of Queue data Structure :

  • Queue is useful in CPU scheduling, Disk Scheduling.
  • Queue is used for synchronization. Examples: IO Buffers, pipes, file IO, etc.

Queue Using Dynamic Array Code:

#include using namespace std; int front,rear; int size; int *Queue; bool isFull() { if (rear==size-1) return true; else return false; } bool isEmpty() { if (front==-1 || front > rear) return true; else return false; } void enqueue(int item) { if (isFull()) cout<<"Queue Overflow \n"; else

if (front==-1) front=0; rear++; Queue[rear]=item; } } int dequeue() { if(isEmpty()) { cout<<"Queue Underflow \n"; return - 1; } else { int item=Queue[front]; front++; return item; } } void traverse() { if(isEmpty()) cout<<"Queue is Empty \n"; else { for(int i=front;i<=rear;i++) cout<<Queue[i]<<" "; } cout<<endl; } void main() { int ch,item; front=rear=-1; cout<<"Enter Queue Size"; cin>>size; Queue=new int [size]; while(true) { cout<<"***************************************\n"; cout<<"1) Insert element to Queue \n"; cout<<"2) Delete element from Queue \n"; cout<<"3) Display all the elements of queue \n"; cout<<"4) Exit \n"; cout<<"***************************************\n"; cin>>ch; switch (ch) { case 1 : cout<<"Enter the item:"; cin>>item; enqueue(item); break; case 2 : cout<<dequeue()<<" Deleted from the Queue \n"; break;