[go: up one dir, main page]

0% found this document useful (0 votes)
120 views5 pages

DSL Assignment 4

Uploaded by

vishalbavdhane44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views5 pages

DSL Assignment 4

Uploaded by

vishalbavdhane44
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignmet Title: Create a Student Record Management System using linked list

Aim: Create a Student Record Management System using linked list


 Use a singly/doubly linked list to store student data (Roll No, Name, Marks).
 Perform operations: Add Delete, Update, Search, and Sort.
 Display records in ascending/descending order based on marks or roll number.

Input: Individual details


Output: Maintained information of the students
Objectives: To maintain student's information by performing different operations like add, delete, update, search,
sort on singly linked list.

Theory:
Linked List:
Definition: A linked list is a sequence of node data structure, which is 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.
Element− Each link of a linked list can store a data called an element.
Next − each link of a linked list contains a link to the next link called Next.

Linked List−A Linked List contains the connection link to the first link called first.
Linked List Representation
Linked list can be visualized as a chain of nodes, where every node points to the next node.

Types of linked list: Following are the various types of linked list.
Singly Linked List−Item navigation is forward only.
Doubly Linked List –Items can be navigated forward and backward.
Circular Linked List−Last item contains link of the first element as next and the first element has a link
to the last element as previous.

Singly linked list


Singly linked list can be defined as the collection of ordered set of elements. The number of elements may vary
according to need of the program. A node in the singly linked list consists of two parts: data part and link part.
Data part of the node stores actual information that is to be represented by the node while the link part of the node
stores the address of its immediate successor. In other words, we can say that each node contains only next pointer,
therefore we cannot traverse the list in the reverse direction.
Advantages of Singly Linked List
There are some advantages of singly Linked List
 It is very easier for the accessibility of a node in the forward direction.
 The insertion and deletion of a node are very easy.
 Less memory requires when compared to doubly, circular or doubly circular linked list.
 The Singly linked list is the very easy data structure to implement.
 During the execution, we can allocate or deallocate memory easily.
 Insertion and deletion of elements don’t need the movement of all the elements when compared to an array.

Disadvantages of Singly Linked List


The disadvantages of singly Linked List are following
 Accessing the preceding node of a current node is not possible as there is no backward traversal.
 The Accessing of a node is very time-consuming.

Operations on Singly Linked List


There are various operations which can be performed on singly linked list. Alistofall suchoperationsis given below.

Node Creation
class StudentNode:
def __init__(self, roll_no, name, marks):
self.roll_no = roll_no
self.name = name
self.marks = marks
self.next = None

class StudentLinkedList:
def __init__(self):
self.head = None

my_list = StudentLinkedList();

Insertion

The insertion into a singly linked list can be performed at different positions. Based on the position of the newnode
being inserted, the insertion is categorized into the following categories.

SN Operation Description

1 Insertion at It involves inserting any element at the front of the list. We just need to a few link
beginning adjustments to make the new node as the head of the list.

2 Insertion at end of It involves insertion at the last of the linked list. The new node can be inserted as the
the list only node in the list or it can be inserted as the last one. Different logics are
implemented in each scenario.

3 Insertion after It involves insertion after the specified node of the linked list. We need to skip the
specified node desired number of nodes in order to reach the node after which the new node will be
inserted. .
Deletion and Traversing

The Deletion of a node from a singly linked list can be performed at different positions. Based on the position of
the node being deleted, the operation is categorized into the following categories.

SN Operation Description

1 Deletion at Itinvolvesdeletionofanodefromthebeginningofthelist.Thisisthesimplest operation


beginning among all. It just need a few adjustments in the node pointers.

2 Deletion at the Itinvolvesdeletingthelastnodeofthelist.Thelistcaneitherbeemptyorfull. Different logic


end of the list is implemented for the different scenarios.

3 Deletion after It involves deleting the node after the specified node in the list. we need to skip the
specified node desired number of nodes to reach the node after which the node will be deleted. This
requires traversing through the list.

4 Traversing In traversing, we simply visit each node of the list at least once in order to perform
some specific operation on it, for example, printing data part of each node present in
the list.

5 Searching In searching, we match each element of the list with the given element. If the element
is found on any of the location then location of that element is returned otherwise
null is returned. .

Sorting:
def display_students(self, sort_by="roll_no", ascending=True):
students = []
current = self.head
while current:
students.append((current.roll_no, current.name, current.marks))
current = current.next

if sort_by == "roll_no":
students.sort(key=lambda x: x[0], reverse=not ascending)
elif sort_by == "marks":
students.sort(key=lambda x: x[2], reverse=not ascending)

if not students:
print(" No records to display.")
return

print("\nStudent Records:")
for s in students:
print(f"Roll No: {s[0]}, Name: {s[1]}, Marks: {s[2]}")

Algorithm

(Writeyourownalgorithmforyourprogram)
Conclusion:

Thus, we have successfully maintained student’s information using singly linked list.

Questions:
1. What is a Linked list?
2. Can you represent a Linked list graphically?
3. How many pointers are required to implement a simple Linked list?
4. How many types of Linked lists are there?
5. How to represent a linked list node?
6. Describe the steps to insert data at the starting of a singly linked list.
7. How to insert a node at the end of Linked list?
8. How to delete a node from linked list?
9. How to reverse a singly linked list?
10. What is the difference between singly and doubly linked lists?
11. What are the applications that use Linked lists?
12. What will you prefer to use a singly or a doubly linked lists for traversing through a list of element

You might also like