Singly Linked List in Python: Objective
Singly Linked List in Python: Objective
Singly Linked List in Python: Objective
Objective
– Understand the concepts of singly linked lists
– Implement singly linked list using dynamic structures
Linked Lists:
A linked list is a data structure consisting of a group of nodes which together represent a
sequence. Under the simplest form, each node is composed of a datum and a reference (in
other words, a link) to the next node in the sequence; more complex variants add additional
links. This structure allows for efficient insertion or removal of elements from any position in the
sequence.
last
first
Representation:
A linked list is represented by a pointer to the first node of the linked list. The first node is called
the head. If the linked list is empty, then the value of the head is NULL.
1) data
# Node class
class Node:
LAB TASK
Consider a scenario where a firm wants to maintain the data of its employees. The data
containing employee number, name, and salary and department # are saved in a singly linked
list.
Emp ID Next
Name
Salary
Dept no
Selective Display: records of the employees having the salary greater than the given value
are displayed
Count: Count the number of employees in a dept.
Split_fun: a function to split the given linked list in two separate lists from the
given position and display the both lists using the display function.
POST LAB
Use this node definition on the questions that follow.
class node:
def __init__(i=0):
info=i
next=None
b. Create a node s. Initialize its info with 7 and its next with node r
c. Create a node t. Initialize its info with 3 and its next with node s
2. Draw a diagram of nodes created in part 1 and display the output on the basis of
following statement:
print( t.info + s.info + r.info)