0% found this document useful (0 votes)
8 views2 pages

22ec8063 Asg3

The document contains a Python implementation of a singly linked list with methods to insert nodes at the beginning and end, as well as to display the list. It defines a Node class for individual elements and a LinkedList class for managing the list. The code demonstrates the functionality by inserting and displaying nodes in various sequences.

Uploaded by

deepanudeep05
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
0% found this document useful (0 votes)
8 views2 pages

22ec8063 Asg3

The document contains a Python implementation of a singly linked list with methods to insert nodes at the beginning and end, as well as to display the list. It defines a Node class for individual elements and a LinkedList class for managing the list. The code demonstrates the functionality by inserting and displaying nodes in various sequences.

Uploaded by

deepanudeep05
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/ 2

Name : Y Praise Son

Roll No : 22EC8063
Reg No : 22U10496

Code:
class Node:
def __init__(self,value):
self.data = value
self.next = None

class LinkedList:
def __init__(self):
self.head = None
def insert_end(self,value):
if(self.head==None):
self.head = Node(value)
return
Newnode = self.head
while(Newnode.next!=None):
Newnode = Newnode.next
Newnode.next = Node(value)
def display(self):
node = self.head
while(node!=None):
print(node.data,end=" ")
node = node.next
print("\n")
def insert_begin(self,value):
node = self.head
self.head = Node(value)
self.head.next = node

ll = LinkedList()
ll.insert_begin(5)
ll.display()
ll.insert_end(60)
ll.insert_begin(66)
ll.display()
ll.insert_begin(56)
ll.insert_begin(88)
ll.insert_end(1000)
ll.insert_begin(7676)
ll.insert_end(10)
ll.insert_begin(767677)
ll.display()
Output:

You might also like