Академический Документы
Профессиональный Документы
Культура Документы
Lab 8
Doubly Linked List and DECK Implementations
Table of Contents
1. Introduction 95
1.1 Doubly Linked Lists 95
1.2 Relevant Lecture Readings 95
4. Concept Map 96
4.1 Doubly Linked Lists in C++ 96
4.2 Double ended queue (DECK): 98
1. Introduction
This lab will introduce concept of dynamic memory based data structures such as linked
lists. In case of some real world applications we don’t know about the storage requirements of
program before program execution, in that scenario dynamic data storage systems are useful. We
will learn about linear, circular and doubly linked list structures and how linked lists are helpful
to store data during program execution.
A doubly linked list is a linked list in which every node has a next pointer and a back
pointer. In other words, every node contains the address of the next node (except the last node),
and every node contains the address of the previous node (except the first node). See Figure 4.
To understand and implement linear linked lists with their operations in C++.
To understand and implement circular linked lists with their operations in C++.
Department of Computer Science Page 95
MAJU, Islamabad
_________________ Lab 8: Doubly Linked List and DECK Implementations
To understand and implement doubly linked lists with their operations in C++.
4. Concept Map
This concept map will help students to understand the main concepts of topic covered in
lab.
Insertion of a node in a doubly linked list involves some cases which are given below:
Following code segment can be used to insert a node in a doubly linked list:
template <class Type>
void doublyLinkedList<Type>::insert(const Type& insertItem)
{
nodeType<Type> *current; //pointer to traverse the list
nodeType<Type> *trailCurrent; //pointer just before current
nodeType<Type> *newNode; //pointer to create a node
bool found;
newNode = new nodeType<Type>; //create the node
newNode->info = insertItem; //store the new item in the
node
newNode->next = NULL;
newNode->back = NULL;
if (first == NULL) //if list is empty, newNode is the only
node
{
first = newNode;
last = newNode;
count++;
}
else
{
found = false;
current = first;
while (current != NULL && !found) //search the list
if (current->info >= insertItem)
found = true;
else
{
trailCurrent = current;
current = current->next;
}
Department of Computer Science Page 96
MAJU, Islamabad
_________________ Lab 8: Doubly Linked List and DECK Implementations
if (first != NULL)
first->back = NULL;
else
last = NULL;
count--;
delete current;
}
else
{
found = false;
current = first;
while (current != NULL && !found) //search the list
if (current->info >= deleteItem)
found = true;
else
current = current->next;
if (current == NULL)
cout << "The item to be deleted is not in "
<< "the list." << endl;
else if (current->info == deleteItem) //check for equality
{
trailCurrent = current->back;
trailCurrent->next = current->next;
if (current->next != NULL)
current->next->back = trailCurrent;
if (current == last)
last = trailCurrent;
count--;
delete current;
}
else cout << "The item to be deleted is not in list."
<<endl;}
On the other hand, a doubly linked list is a concrete data structure, i.e. its implementation would
be same for every programmer. It is a way for storing data.
After studying the introduction and concept map sections you should be ready to provide
the solution of following problems. Design the solutions of the problems in C++ and
bring your code to lab so that lab instructor should assess and grade it.
Write a program of doubly linked list of objects of “person” class. Attributes of “person”
class (privately defined) are per_id (int), per_name (string) and per_age (int). “person”
class contains member functions (publicly defined): constructor, input and output
functions. You are required to define a class for doubly linked list. This class should
contain the member functions to insert, delete nodes from linked list. This class should
also contain the member functions to display values of all nodes of linked list.
5.3.1 Task-1
Compare linear linked list with doubly linked list and provide three differences between
the two structures.
5.3.2 Task-2
List three real world examples in which doubly linked list structures can be used.
6.1 Tools
This linked list program provides different functions like addition of node at start of list,
deletion of node from list, displaying elements of list.
7. Practice Tasks
This section will provide information about the practice tasks which are required to be performed
in lab session. Design solutions of problems discussed in each task and place solution code in a
folder specified by your lab instructor.
Write a program which should implement a doubly linked list. Elements of this doubly linked list
should be of float type, user will provide values as input for elements of this doubly linked list.
Your program should Remove Duplicate nodes in DLL.
After completing this lab, student will be able to understand and develop programs related to
linear linked lists, circular linked lists and doubly linked lists in C++ using Microsoft Visual
Studio 2008 environment.
9. Evaluation criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each
task is assigned the marks percentage which will be evaluated by the instructor in the lab whether
the student has finished the complete/partial task(s).