0% found this document useful (0 votes)
11 views4 pages

Lab 02 Updated

This document discusses implementing circular and doubly linked lists in C++. It covers the objectives, software, and introductions to circular and doubly linked lists. It provides examples of their advantages and implementations. It outlines lab tasks to create functions for inserting, displaying, and deleting nodes for both list types and to solve problems like storing student data and searching.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Lab 02 Updated

This document discusses implementing circular and doubly linked lists in C++. It covers the objectives, software, and introductions to circular and doubly linked lists. It provides examples of their advantages and implementations. It outlines lab tasks to create functions for inserting, displaying, and deleting nodes for both list types and to solve problems like storing student data and searching.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Computer Science Islamia University Bahawalpur

Subject: Data Structures Instructor: M.Usman Ghani

Lab 2-3

Circular And Doubly Linked List Implementation In C++

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:

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.

Advantages Of Circular Linked List:

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.

Doubly Linked 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

Advantages over singly linked list:

1) A DLL can be traversed in both forward and backward direction.

2) The delete operation in DLL is more efficient if pointer to the node to be deleted is given.

3) We can quickly insert a new node before a given node.

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:

1) Make a circular linked list with following functions:

 Insert Link function

 Display function

 Delete Node function

Pseudocode to insert in the front of single list is given, think about other functions

2) By using the above function solve josephus problem.


Create class named student

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

3) Make a function in above program to search student by its:

 Roll Number

 Name

4) Make a doubly linked list with following functions(you can take help from lecture notes):

 Insert Link function

 Display function

 Delete Node 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.

5) Make a function in above program to give the student name with:

 Smallest Roll Number

 Highest Roll Number

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.

Post lab Task:

1) Write practical applications of doubly linked list.

You might also like