dsa
dsa
CA 2 ASSIGNMENT
Name: Supratik Mitra
University Roll Number:25500123169
University Registration Number:232550110319
Year:2nd
Semester:3rd
Section: C
Topic Name: Linked List and Its Types
Subject Name: Data Structures and Algorithm
Subject Code: PCC-CS301
Deparment: Computer Science and Engineering
Linked lists are key data structures used for storing and organizing
collections of elements efficiently. Unlike arrays, they can dynamically
adjust their size, allowing flexible memory use. Linked lists consist of
nodes, where each node holds data and a pointer to the next node in the
sequence.
There are different types of linked lists, each serving specific purposes:
1. Single Linked List: This basic form of a linked list connects each node to
the next in sequence. It allows efficient additions and deletions at the
start but can be slower when accessing or modifying nodes in the middle.
2.Double Linked List: Each node has two pointers—one to the next node
and one to the previous. This allows easy traversal in both directions and
makes deleting nodes simpler compared to single linked lists.
3. Circular Linked List: In this variation, the last node connects back to the
first, creating a loop. Circular linked lists are useful for tasks that require
continuous traversal, like round-robin scheduling or circular buffers.
previous->next = current->next;
printf("Element with value %d at position %d
Single Linked list: Output
Double linked list: source code
#include <stdio.h> switch (choice) {
#include <stdlib.h> case 1:
void remove_first(); append_end();
void append_end(); break;
struct element { case 2:
struct element* previous;
remove_first();
struct element* next;
break;
int value;
case 3:
};
exit(0);
struct element* start = NULL;
default:
int main() {
printf("Invalid
int choice;
choice!\n");
while (1) {
}
printf("\nEnter your
}
choice:\n");
printf("1. Add at end \n");
printf("2. Remove from return 0;
start\n"); }
printf("3. Exit\n");
scanf("%d", &choice);
Double linked list: source code (Continued)
void append_end() { void remove_first() {
struct element *new_node, *current;
struct element *temp;
int num;
if (start == NULL) {
new_node = (struct element*)malloc(sizeof(struct element));
return; } else {
} else { if (start->next == NULL) {
printf("Enter the value: "); printf("%d is removed\n",
scanf("%d", &num); start->value);
new_node->value = num; free(start);
if (start == NULL) {
start = NULL;
new_node->previous = NULL;
} else {
new_node->next = NULL;
start = new_node;
temp = start;
new_node->next = NULL; }
printf("%d is added at the end\n", num);
}}
}
Double linked list: Output
Circular linked list(Using double
linked list): source code
~ Supratik Mitra
-Thank You!
CONCLUSION
In conclusion, delving into the topic of Linked Lists and
Their Types has significantly broadened my understanding
of data structures and their applications. Mastering the
implementation and manipulation of linked lists has
enhanced my ability to tackle various programming
challenges efficiently. This project has been a crucial part
of my academic development, providing a robust
foundation in data structures and deepening my
appreciation for their practical utility in software
development.