Data Structures and Algorithm
Data Structures and Algorithm
1
Representation of a Linked List
A singly linked list is a type of linked list that is unidirectional, that is,
it can be traversed in only one direction from head to the last node
(tail). Each element in a linked list is called a node.
2
3. Circular Linked List :
A circular linked list is a type of linked list in which the first and the
last nodes are also connected to each other to form a circle. Here, the
address of the last node consists of the address of the first node.
Motivation
Why do we need Linked Lists?
1. Image viewer – Previous and next images are linked, hence can be
accessed by next and previous button.
2. Previous and next page in web browser – We can access previous
and next url searched in web browser by pressing back and next button
since, they are linked as linked list.
3. Music Player – Songs in music player are linked to previous and next
song. you can play songs either from starting or ending of the list.
3
Methodology
In a linked list, operations such as traversal, insertion, deletion,
search and sort can be performed. Some of the operations are
mentioned below.
Operations Of a Linked List :
• IsEmpty( ) :
➢ Determine whether or not the list is empty
• InsertNode :
➢ Insert a new node at a particular position
• DeleteNode :
➢ Delete a node with a given value.
• DisplayList :
➢ Print all the nodes in the list
• FindNode :
➢ Returns the position of the node.
Illustration
Output:
4
In the above program, created a singly linked list and display all the
nodes present in the list.
Algorithm
1. Create a class Node which has two attributes: data and next.
Next is a pointer to the next node.
2. Create another class which has two attributes: head and tail.
3. addNode() will add a new node to the list:
1. Create a new node.
2. It first checks, whether the head is equal to null which
means the list is empty.
3. If the list is empty, both head and tail will point to the
newly added node.
4. If the list is not empty, the new node will be added to end
of the list such that tail's next will point to the newly added
node. This new node will become the new tail of the list.
4. display() will display the nodes present in the list:
1. Define a node current which initially points to the head of the
list.
2. Traverse through the list till current points to null.
3. Display each node by making current to point to node next
to it in each iteration.
5
Illustration
Output
In the above program, we created a singly linked list and delete an element
and then the sorted list is displayed present in the list.
Conclusion
In this report, I got to know about “Linked List in data structure” of “Data
Structure and Algorithms”. I got to know that a Linked List is a linear data
structure that are connected through a series of nodes. And, each node
contains the data items and address to the next node. Most importantly, we
could understand that with the help of real-life problems. We are also aware
of the advantages and applications of using Linked List in data structure.
There are various operations of an Linked List which can be performed in C.
This was an informative project and would help me in future.
6
7