67% found this document useful (3 votes)
3K views18 pages

Linked List Project Report

The document describes a project to develop a linked list data structure using C programming language. It was submitted by four students - Ayush Sasane, Sanket Thorat, Pranav Salunke and Siddharth Salve - for their diploma in computer technology. The project aims to implement basic linked list operations like traversal, insertion, deletion and demonstrate their working. It discusses the rationale, benefits, outcomes achieved, literature review, methodology, resources required and skills developed through the project. The document also explains the working of different types of linked lists and various linked list operations like traversal, insertion, deletion, search and sorting through examples in C code.

Uploaded by

Ayush Sasane
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
67% found this document useful (3 votes)
3K views18 pages

Linked List Project Report

The document describes a project to develop a linked list data structure using C programming language. It was submitted by four students - Ayush Sasane, Sanket Thorat, Pranav Salunke and Siddharth Salve - for their diploma in computer technology. The project aims to implement basic linked list operations like traversal, insertion, deletion and demonstrate their working. It discusses the rationale, benefits, outcomes achieved, literature review, methodology, resources required and skills developed through the project. The document also explains the working of different types of linked lists and various linked list operations like traversal, insertion, deletion, search and sorting through examples in C code.

Uploaded by

Ayush Sasane
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/ 18

Sanjivani Ruler Education Society’s

SANJIVANI K.B.P. POLYTECHNIC, KOPARGAON

A project report on

“DEVELOP A PROJECT TO DEMONSTRATE


LINKED LIST”
SUBJECT: Data Structures using ‘C’

SUBMITTED BY
232 Ayush Sasane
246 Sanket Thorat
226 Pranav Salunke

228 Siddharth Salve

Guided by: V.A. Parjane


DEPARTMENT OF COMPUTER TECHNOLOGY
Sanjivani Ruler Education Society’s

SANJIVANI K.B.P. POLYTECHNIC, KOPARGAON

CERTIFICATE
This is to certify that the Project report entitled

“DEVELOP A PROJECT TO DEMONSTRATE LINKED LIST”

SUBMITTED BY
232 Ayush Sasane
246 Sanket Thorat
226 Pranav Salunke

228 Siddharth Salve


Under the supervision and guidance for partial fulfillment of
the requirement for Diploma in Computer Technology
affiliated to Maharashtra State Board of Technical Education,
Mumbai.
PROJECT GUIDE HOD PRINCIPAL
PROF. V.A. Parjane PROF. G.N. JORVEKAR PROF. A.R.MIRIKAR
Report Micro – Project
Title: LINKED LIST

1.0 Rationale:

Linked List is a very commonly used linear data structure


which consists of group of nodes in a sequence. Each node
holds its own data and the address of the next node hence
forming a chain like structure. Linked Lists are used to create
trees and graphs.

2.0 Aims /Benefits of micro project:

The principal benefit of a linked list over a conventional array


is that the list elements can be easily inserted or removed
without reallocation or reorganization of the entire structure
because the data items need not be stored contiguously in
memory or on disk, while restructuring an array at run-time is
a much more expensive operation. Linked lists allow insertion
and removal of nodes at any point in the list, and allow doing
so with a constant number of operations by keeping the link
previous to the link being added or removed in memory during
list traversal.

3.0 Course Outcomes Achieved:

3a. Create relevant structure to represent the given node using


linked list.
3b. Develop algorithm to insert the given item in linear
linked list.
3c. Develop algorithm to delete the given item from linear
linked list. 3d. Develop algorithm to traverse a circular linked
list.
4.0 Literature review:

A linked list is a sequence of data structures, which are


connected together via links.
Linked List is a sequence of links which contains items. Each
link contains a connection to another link. Linked list is the
second most-used data structure after array. Following are the
important terms to understand the concept of Linked List.

5.0 Actual Methodology followed:

1. Making group of maximum 4 members.


2. Choosing Specific topic.
3. Work distribution.
4. Collect the information with relating.
5. Discussion with teachers.
6. With the help of internet, teachers and laptop make a
report on this topic.
7. Arranging collected Information as per given Format.
8. Preparing presentation.
9. Clear the submission process.

6.0. Actual Resources Required:

Sr. no Name of resources Specifications Quantit Marks


y
1. Computer Intel (R) core i3-4 GB RAM 1
2. Development tools Dos box Turbo C++ 1
7.0. Skill developed:
10. Project management plan
11. Communication plan
12. Schedule baseline
13. Managing people and encouraging them
14. Scope baseline
15. Motivational skills
16. Presentation skill
17. Problem solving skills
18. Team work skill

8.0. Application of this Project

19. Implementation of stacks and queues


20. Implementation of graphs: Adjacency list representation of
graphs is most popular which is uses linked list to store
adjacent vertices.
21. Dynamic memory allocation: We use linked list of free
blocks.
22. Maintaining directory of names
23. Performing arithmetic operations on long integers
24. Manipulation of polynomials by storing constants in the
node of linked list
25. representing sparse matrices
26.
9.0 Working of linked list

27. A linked list is a linear data structure, in which the


elements are not stored at contiguous memory locations. It
is a collection of some nodes containing homogeneous
elements. Each node consists of a data part and one or
more address part depending upon the types of linked list.

TYPES OF LINKED LIST

1) Singly Linked List [Linear linked list]


It is the most common. Each node has data and a pointer to the next node.

2) Doubly Linked List


We add a pointer to the previous node in a doubly-linked list. Thus, we
can go in either direction: forward or backward.

3) Circular Linked List


A circular linked list is a variation of a linked list in which the last
element is linked to the first element. This forms a circular loop.
LINKED LIST TERMINOLOGIES

➢ Node
➢ Address
➢ Pointer
➢ Information field/Data field
➢ Next pointer
➢ Null pointer
➢ Empty list

LINKED LIST OPERATIONS:

1) TRAVERSE 2) INSERT 3) DELETE

There are various linked list operations that allow us to perform different
actions on linked lists. For example, the insertion operation adds a new element
to the linked list.

Here's a list of basic linked list operations that we will cover in this article.

• Traversal - access each element of the linked list


• Insertion - adds a new element to the linked list
• Deletion - removes the existing elements
• Search - find a node in the linked list
• Sort - sort the nodes of the linked list

THINGS TO REMEMBER ABOUT LINKED LIST

• head points to the first node of the linked list


• next pointer of the last node is NULL, so if the next current node is
NULL, we have reached the end of the linked list.
In all of the examples, we will assume that the linked list has three nodes
1--->2 --->3 with node structure as below
TRAVERSE A LINKED LIST

Displaying the contents of a linked list is very simple. We keep moving


the temp node to the next one and display its contents.
When temp is NULL, we know that we have reached the end of the linked
list so we get out of the while loop.

The output of this program will be:

INSERT ELEMENTS TO A LINKED LIST

You can add elements to either the beginning, middle or end of the
linked list

INSERT AT THE BEGINNING

• Allocate memory for new node

• Store data
• Change next of new node to point to head

• Change head to point to recently created node

INSERT AT THE END


• Allocate memory for new node

• Store data

• Traverse to last node

• Change next of last node to recently created node

INSERT AT THE MIDDLE


• Allocate memory and store data for new node

• Traverse to node just before the required position of new node

Change next pointers to include new node in between


DELETE FROM A LINKED LIST

You can delete either from the beginning, end or from a particular
position.

DELETE FROM BEGINNING

Point head to the second node

DELETE FROM END

• Traverse to second last element

• Change its next pointer to null


DELETE FROM MIDDLE

• Traverse to element before the element to be deleted

• Change next pointers to exclude the node from the chain

SEARCH AN ELEMENT ON A LINKED LIST

You can search an element on a linked list using a loop using the
following steps. We are finding item on a linked list.

• Make head as the current node.

• Run a loop until the current node is NULL because the last element points
to NULL.

• In each iteration, check if the key of the node is equal to item. If it the key
matches the item, return true otherwise return false.

SORT ELEMENTS OF A LINKED LIST


We will use a simple sorting algorithm, Bubble Sort, to sort the elements of a
linked list in ascending order below.
1. Make the head as the current node and create another node index for later
use.

2. If head is null, return.

3. Else, run a loop till the last node (i.e. NULL).

4. In each iteration, follow the following step 5-6.

5. Store the next node of current in index.


6. Check if the data of the current node is greater than the next node. If it is
greater, swap current and index.

10.0. Linked list operation in C

// Linked list operations in C


#include <stdio.h>
#include <stdlib.h>

// Create a node
struct Node {
int data;
struct Node* next;
};

// Insert at the beginning


void insertAtBeginning(struct Node** head_ref, int new_data) {
// Allocate memory to a node
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));

// insert the data


new_node->data = new_data;

new_node->next = (*head_ref);

// Move head to new node


(*head_ref) = new_node;
}

// Insert a node after a node


void insertAfter(struct Node* prev_node, int new_data) {
if (prev_node == NULL) {
printf("the given previous node cannot be NULL");
return;
}

struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));


new_node->data = new_data; new_node->next = prev_node->next;
prev_node->next = new_node;
}

// Insert the the end


void insertAtEnd(struct Node** head_ref, int new_data) { struct
Node* new_node = (struct Node*)malloc(sizeof(struct Node)); struct
Node* last = *head_ref; /* used in step 5*/

new_node->data = new_data;
new_node->next = NULL;

if (*head_ref == NULL) {
*head_ref = new_node;
return;
}

while (last->next != NULL) last = last->next;

last->next = new_node;
return;
}

// Delete a node void deleteNode(struct Node**


head_ref, int key) {
struct Node *temp = *head_ref, *prev;

if (temp != NULL && temp->data == key) {


*head_ref = temp->next;
free(temp); return;
}
// Find the key to be deleted while (temp !=
NULL && temp->data != key) {
prev = temp;
temp = temp->next;
}

// If the key is not present


if (temp == NULL) return;

// Remove the node


prev->next = temp->next;
free(temp);
}

// Search a node int searchNode(struct Node**


head_ref, int key) {
struct Node* current = *head_ref;

while (current != NULL) { if


(current->data == key) return 1;
current = current->next;
}
return 0;
}

// Sort the linked list


void sortLinkedList(struct Node** head_ref) {
struct Node *current = *head_ref, *index = NULL;
int temp;

if (head_ref == NULL) {
return; } else {
while (current != NULL) {
// index points to the node next to current
index = current->next;

while (index != NULL) { if


(current->data > index->data) {
temp = current->data; current-
>data = index->data;
index->data = temp;
}
index = index->next;
}
current = current->next;
}
}
}
// Print the linked list void
printList(struct Node* node) {
while (node != NULL) { printf("
%d ", node->data);
node = node->next;
}
}

// Driver program int


main() {
struct Node* head = NULL;

insertAtEnd(&head, 1);
insertAtBeginning(&head, 2);
insertAtBeginning(&head, 3); insertAtEnd(&head,
4);
insertAfter(head->next, 5);

printf("Linked list: ");


printList(head);

printf("\nAfter deleting an element: ");


deleteNode(&head, 3);
printList(head);

int item_to_find = 3; if
(searchNode(&head, item_to_find)) {
printf("\n%d is found", item_to_find);
} else {
printf("\n%d is not found", item_to_find);
}

sortLinkedList(&head);
printf("\nSorted List: ");
printList(head);
}
11.0. Output of the program

12.0. Conclusion

Linked lists are the data structures that are used to store data items in a linear
fashion but non-contiguous locations. A linked list is a collection of nodes that
contain a data part and a next pointer that contains the memory address of the
next element in the list.

The last element in the list has its next pointer set to NULL, thereby indicating
the end of the list. The first element of the list is called the Head. The linked list
supports various operations like insertion, deletion, traversal, etc. In case of
dynamic memory allocation, linked lists are preferred over arrays.

Linked lists are expensive as far as their traversal is concerned since we cannot
randomly access the elements like arrays. However, insertion-deletion operations
are less expensive when compared arrays.
We have learned all about linked lists in this project.

You might also like