CH 4.5 - Linked Stack and Queue
CH 4.5 - Linked Stack and Queue
Data Structures
MyStack Top
2 next
newNode MyStack Top
H H
Y Y
H
next next
next next
next
C
1 X C
1 X
NULL NULL
C
next next
next
K K
K
next next
next
NULL NULL
NULL
2.top = top.next;
H H H
C C C
K K K
9
Faculty of Information Technology - Computer Science Department
Queue Representation (re-visited)
• A Queue is a structure in which elements are added to the rear and removed
from the front. First-In-First-Out (FIFO) structure.
• A front pointer will point to the first node of the queue, and a rear pointer will point to
the last node of the queue.
1. rear.next = newNode;
2. rear = newNode;
1. temp = front.element;
2. front = front.next;
If the queue is empty set the rear to null.
14
Faculty of Information Technology - Computer Science Department
Linked Queue Class Implementation
Radix sort is one of the sorting algorithms used to sort a list of integer numbers.
In the radix sort algorithm, a list of integer numbers will be sorted based on the digits of
individual numbers.
Sorting is performed from the least significant digit to the most significant digit.
Radix sort algorithm requires the number of passes which are equal to the number of digits
present in the largest number among the list of numbers.
For example, if the largest number is a 3-digit number then that list is sorted with 3 passes.
Step-by-Step Process
The Radix sort algorithm is performed using the following steps:
Step 1 - Define 10 queues each representing a bucket for each digit from 0 to 9.
Step 2 - Consider the least significant digit of each number in the list which is to be sorted.
Step 3 - Insert each number into its respective queue based on the least significant digit.
Step 4 - Group all the numbers from queue 0 to queue 9 in the order they have inserted.
Step 5 - Repeat starting from step 3 based on the next least significant digit until all the
numbers are grouped based on the most significant digit.
Faculty of Information Technology - Computer Science Department 17
Queue Application: Radix Sort
Example
Sort the following integer numbers using Radix Sort Algorithm:
Example
Example
Example