You are on page 1of 4

Data Structures and Algorithms

CL210
LABORATORY MANUAL
Fall 2021

LAB 04
Stacks and Queues
Engr. Shahid Qureshi

________________________________________ __________ ___


STUDENT NAME ROLL NO SEC

______________________________________
LAB ENGINEER SIGNATURE & DATE

MARKS AWARDED: /50


________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES (NUCES), ISLAMABAD

Prepared by: Engr. Shahid Qureshi Date: 24 Sep, 2021


1. Learning Objectives:
● Modify the link list to make it efficient
● Create a doubly link list

2. Equipment Required:
A working computer having Visual Studio or any other good compiler Installed.

3. Stack data structure:


A Stack is a special kind of list in which all insertions and deletions take place at one end,
called the Top. Other Names for the stacks are Pushdown List or Last In First Out (LIFO).
Common operations on Stacks are:
 TOP(): Return the element at the top of stack S.
 POP(): Remove the top element of the stack.
 PUSH(S): Insert the element x at the top of the stack.
 ISEMPTY(): To check if stack is empty or not
 ClearStack();

Example:

4. Queue data structure:


A Queue is a linear data structure, where items are inserted at one end (the rear) and deleted
at the other end (the front). It is also called a First In First Out (FIFO).
Common operations on Stacks are:
 PUSH(x): Inserts element x at the end of Queue. Also known as Enqueue
 POP(): Deletes the first element of the Queue. Also known as Dequeue
 FRONT(): Returns the first element on Queue
 ISEMPTY(): Returns true if its an empty queue

Priority Queue
A priority queue allows entries to be retrieved according to some specified priority levels.
The highest priority entry is removed first
Entries with equal priority can be removed according to FIFO as queue.

Lab Tasks (Submission guidelines at the end)

Link list implementation for the Stack is provided with the lab manual.

1. Develop a program which can evalueate a postfix mathematical expression using the stacks as
illustrated in the lecture slides.

2. Implement a Priority Queue as illustrated in the diagram given above. Code for the simple
queue is given in the slides. You need to modify it to accommodate a priority number for every
data item. Here is the modification you need to do:

struct QueueNode
{
int priority;
int info;
QueueNode *link;
}

Test your priority queue implementation by pushing data of various priority levels, and then
popping out some data.
Submission:

 Submit your codes on google classroom within deadline.


 Add a comment section at the start of each code file, where you will mention your name,
roll number, lab task#, and brief description of your code
 Name/rename your submission files as “Lab#-Task#-roll#.cpp”, e.g., “Lab02-Task01-20-
955.cpp”.

You might also like