Green University of Bangladesh
Department of Software Engineering (SWE)
Faculty of Science and Engineering
Semester: Spring-2025, BSc in SWE (Day)
Lab Report NO: 04
Course Title: Data Structures and Algorithms Lab
Course Code: SWE 108 Section: 242_D2
Lab Experiment Name: Linked Lists: Implementation and Operations
Student Details
Name ID
Tayebur Rahman 242034017
Lab Date :
Submission Date : 02/03/2025
Course Teacher Name : ABRAR HASAN
Lab Report Status
Marks: …………………………. Signature: …………………………
Comments: …………………….. Date: ………………………………
Title of the Lab Report Experiment
Linked Lists: Implementation and Operations
Objectives/Aim
The aim of this report is to:
1. Implement and test different types of linked lists: Singly, Doubly, and
Circular.
2. Perform various operations like insertion, deletion, and traversal.
3. Understand the internal structure and use cases of linked lists.
Procedure / Design
Singly Linked List Flowchart:
1. Start
2. Create a node with data and a pointer to the next node.
3. Add, remove, and display elements step by step.
4. End
Implementation
Singly Linked List:
#include <iostream>
using namespace std;
struct Node
{
int data;
Node* next;
};
int main()
{
Node* head = nullptr;
Node* first = new Node();
Node* second = new Node();
Node* third = new Node();
first->data = 1;
first->next = second;
second->data = 2;
second->next = third;
third->data = 3;
third->next = nullptr;
Node* temp = head = first;
while (temp != nullptr)
{
cout << temp->data << " ";
temp = temp->next;
}
return 0;
}
Doubly Linked List:
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
Node* prev;
};
int main() {
Node* head = nullptr;
Node* first = new Node();
Node* second = new Node();
Node* third = new Node();
first->data = 1;
first->next = second;
first->prev = nullptr;
second->data = 2;
second->next = third;
second->prev = first;
third->data = 3;
third->next = nullptr;
third->prev = second;
Node* temp = head = first;
cout << "Forward Traversal: ";
while (temp != nullptr) {
cout << temp->data << " ";
temp = temp->next;
}
temp = third;
cout << "\nBackward Traversal: ";
while (temp != nullptr) {
cout << temp->data << " ";
temp = temp->prev;
}
return 0;
}
Output
Output(Singly):
Output(Doubly):
Discussion
1. Dynamic Memory Management:
o Linked lists grow and shrink as needed, unlike arrays.
2. Performance:
o Fast insertions and deletions, but slower access compared to arrays.
3. Key Learnings:
o How pointers work and the flexibility of linked list
Practical Applications:
1. Dynamic Memory Management:
o Linked lists grow and shrink as needed, unlike arrays.
2. Performance:
o Fast insertions and deletions, but slower access compared to arrays.
3. Practical Applications:
o Singly Linked List: Useful for dynamic memory allocation and
stacks/queues.
o Doubly Linked List: Ideal for scenarios needing two-way
traversal, like a music playlist.
o Circular Linked List: Suitable for applications like round-robin
scheduling.
4. Challenges Faced:
o There were no significant challenges encountered during the
implementation of basic linked list operations.
5. Most Difficult Parts of the Implementation:
o The most difficult part was properly handling pointers, especially in
deletion and circular traversal.
6. Enjoyable Aspects:
o It was interesting to build the linked lists step by step and see how
nodes link together.
7. Key Learnings:
o The key takeaway is understanding the pointer manipulation in
linked lists and how they differ from arrays in memory handling.
Mapping of Objectives:
The objectives were achieved by successfully implementing and testing the
linked list operations, analyzing their behaviors, and understanding their
practical applications.