A QUEUE Is Logically A First in First Out (FIFO or First Come First Serve) Linear Data Structure
A QUEUE Is Logically A First in First Out (FIFO or First Come First Serve) Linear Data Structure
structure.
It is a homogeneous collection of elements in which new elements are added at one end called
REAR
the existing elements are deleted from other end called FRONT.
Push operation will insert (or add) an element to queue, at the rear end, by incrementing the
array index.
Pop operation will delete (or remove) from the front end by decrementing the array index and
will assign the deleted value to a variable.
Total number of elements present in the queue is FRONT REAR + 1,
CIRCULAR QUEUE is one in which the insertion of a new element is done at the very first
location of the queue if the last location at the queue is full.
DEQUE is a homogeneous list in which elements can be added or inserted (called push
operation) and deleted or removed from both the ends (which is called pop operation).
DOUBLE ENDED QUEUE is we can add a new element at the rear or front end and also
we can remove an
element from both front and rear end.
There are two types of deque depending upon the restriction to perform insertion or
deletion operations at the two ends.
1. Input restricted deque
2. Output restricted deque
input restricted deque is a deque, which allows insertion at only 1 end, rear end, but allows
deletion at both ends, rear and front end of the lists.
output-restricted deque is a deque, which allows deletion at only one end, front end, but
allows insertion at both ends, rear and front ends, of the lists.
There are 4 possible operations performed on deque is
1. Add an element at the rear end
2. Add an element at the front end
3. Delete an element from the front end
4. Delete an element from the rear end
Only 1st, 3rd and 4th operations are performed by input-restricted deque and 1st, 2nd and 3rd
operations are performed by output-restricted deque.
Memory is allocated for the variable during the compilation of a program, then it is fixed and
cannot be changed.
Linked List
Provides a more flexible storage system and it does not require the use of arrays
A linear collection of specially designed data elements.
Nodes
Specially designed data elements.
Each node is divided into two parts:
1. The first part contains the information of the element.
2. The second part contains the address of the next node of the linked list
Linked or next field - Address part of the code
ADVANTAGES:
1. Linked list are dynamic data structure. That is, they can grow or shrink during the execution of
a program.
2. Efficient memory utilization: In linked list (or dynamic) representation, memory is not pre-
allocated. Memory is allocated whenever it is required. And it is deallocated (or removed) when it
is not needed
3. Insertion and deletion are easier and efficient. Linked list provides flexibility in inserting a data
item at a specified position and deletion of a data item from the given position.
4. Many complex applications can be easily carried out with linked list.
DISADVANTAGES:
1. More memory: to store an integer number, a node with integer data and address field is
allocated. That is more memory space is needed.
2. Access to an arbitrary data item is little bit cumbersome and also time consuming.
Creation operation is used to create a linked list. Once a linked list is created with one node,
insertion operation can be used to add more elements in a node.
Insertion operation is used to insert a new node at any specified location in the linked list.
A new node may be inserted :
(a) At the beginning of the linked list
(b) At the end of the linked list
(c) At any specified position in between in a linked list Deletion operation is used to delete
an item (or node) from the linked list.
All the nodes in a singly linked list are arranged sequentially by linking with a pointer.
A singly linked list can grow or shrink, because it is a dynamic data structure.
DOUBLY LINKED LIST is one in which all nodes are linked together by multiple links which help
in accessing both the successor (next) and predecessor (previous) node for any arbitrary node
within the list.
NODE in the priority queue will contain DATA, PRIORITY and NEXT field.
DATA field will store the actual information;
PRIORITY field will store its corresponding priority of the DATA and NEXT will store the address
of the next node.