Data Structures Unit 1-Linear Structures
Data Structures Unit 1-Linear Structures
DATA STRUCTURES
Unit 1-Linear structures
Year/Sem : II/III
Subject Code: 1151CS102
Topic : Queue ADT
Faculty Name : Mrs.S.Vijitha
Date : 17.08.2020
School of Computing
Vel Tech Rangarajan Dr. Sagunthala R&D Institute of
Science and Technology
Contents
and Project
Management
(SEPM)
and Project
For example, people waiting in line for a rail ticket
Management
(SEPM)
form a queue.
07/09/2021 Department of Computer Science and Engineering
Queue - Examples
Examples of queue in "real life":
07/09/2021
Department of Computer Science and Engineering
Queue - Operations
Operations:
07/09/2021
Department of Computer Science and Engineering
Queue - operations
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Enqueue Operation:
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Algorithm:
procedure enqueue(data)
if queue is full
return overflow
endif
rear ← rear + 1
queue[rear] ← data
return true
end procedure
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Code:
rear = rear + 1;
queue[rear] = data;
return 1;
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Dequeue Operation:
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Algorithm:
procedure dequeue
if queue is empty
return underflow
end if
data = queue[front]
front ← front + 1
return true
end procedure
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Code:
int dequeue()
{
if(isempty())
return 0;
int data = queue[front];
front = front + 1;
return data;
}
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Peek():
Algorithm
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Code:
int peek()
{
return queue[front];
}
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Isfull():
Algorithm
begin procedure isfull
if rear equals to MAXSIZE
return true
else
return false
endif
end procedure
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Code:
bool isfull()
{
if(rear == MAXSIZE)
return true;
else
return false;
}
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Isfull():
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Isempty():
Algorithm:
begin procedure isempty
if front is less than min or zero
return true
else
return false
endif
end procedure
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Code:
bool isempty()
{
if(front < 0 || front = 0)
return true;
else
return false;
}
07/09/2021
Department of Computer Science and Engineering
Queue - operations
Isempty():
07/09/2021
Department of Computer Science and Engineering
Queue - Implementation
Implementation:
Using array
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
Insertion:
void insert (int queue[], int max, int front, int rear, int item)
{
if (rear == max - 1)
{
printf("overflow");
}
else
{
if(front == -1 && rear == -1)
{ and Project
front = 0; Management
(SEPM)
rear = 0;
}
07/09/2021 Department of Computer Science and Engineering
Array implementation of queue
Code:
else
{
rear = rear + 1;
}
queue[rear]=item;
}
}
and Project
Management
(SEPM)
Algorithm
int delete (int queue[], int max, int front, int rear)
{
int y;
if (front == -1 || front > rear)
{
printf("underflow");
} and Project
Management
(SEPM)
} (SEPM)
}
07/09/2021 Department of Computer Science and Engineering
Linked list implementation of queue
In the linked queue, there are two pointers
maintained in the memory i.e. front pointer and
rear pointer.
and Project
Management
(SEPM)
Insert operation:
else
{
rear -> next = ptr;
rear = ptr;
rear->next = NULL;
}
}
}
and Project
Management
(SEPM)