Lab 02 Updated
Lab 02 Updated
Lab 2-3
Objectives:
Understanding Circular Linked List and implement it in C++
Understanding Doubly Linked List, and perform tasks
Software:
Dev-Cpp
Microsoft Visual Studio/ Visual Studio Code
Introduction:
This lab is designed to make students understand the basics of circular linked list, doubly linked list, and
their implementation in C++ . Circular linked list is the one whose next address points towards the address
of the first link in the linked list, whereas, in doubly linked list, there is an information of previous address
as well. Both of circular and doubly linked list are very important in various applications.
Circular linked list is a linked list where all nodes are connected to form a circle. There is no NULL at
the end. A circular linked list can be a singly circular linked list or doubly circular linked list.
Department of Computer Science Islamia University Bahawalpur
Subject: Data Structures Instructor: M.Usman Ghani
Why Circular? In a singly linked list, for accessing any node of linked list, we start
traversing from the first node. If we are at any node in the middle of the list, then it is not possible to
access nodes that precede the given node. This problem can be solved by slightly altering the structure
of singly linked list. In a singly linked list, next part (pointer to next node) is NULL, if we utilize this
link to point to the first node then we can reach preceding nodes. Refer this for more advantages of
circular linked lists.
1) Any node can be a starting point. We can traverse the whole list by starting from any point. We just
need to stop when the first visited node is visited again.
2) Circular lists are useful in applications to repeatedly go around the list. For example, when multiple
applications are running on a PC, it is common for the operating system to put the running applications
on a list and then to cycle through them, giving each of them a slice of time to execute, and then making
them wait while the CPU is given to another application. It is convenient for the operating system to use
a circular list so that when it reaches the end of the list it can cycle around to the front of the list.
A Doubly Linked List (DLL) contains an extra pointer, typically called previous pointer, together with
next pointer and data which are there in singly linked list.
Department of Computer Science Islamia University Bahawalpur
Subject: Data Structures Instructor: M.Usman Ghani
2) The delete operation in DLL is more efficient if pointer to the node to be deleted is given.
4) In singly linked list, to delete a node, pointer to the previous node is needed. To get this previous node,
sometimes the list is traversed. In DLL, we can get the previous node using previous pointer.
In Lab Tasks:
Display function
Pseudocode to insert in the front of single list is given, think about other functions
In this class add the student name, roll number, and department information, and make their gather, setters.
(Later we use this class to create objects that will store in list )
Department of Computer Science Islamia University Bahawalpur
Subject: Data Structures Instructor: M.Usman Ghani
Roll Number
Name
4) Make a doubly linked list with following functions(you can take help from lecture notes):
Display function
In data section add student name, roll number and department information.Your program must be generic,
i-e program should not close before the user doesn’t allow to exit.
6) Write a program for doubly linked list to save student name and its roll number in ascending order of
the linked list i-e The student with roll number smaller will be in the first link and student with highest
roll number will be in the last link.