-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathusing python
More file actions
38 lines (32 loc) · 904 Bytes
/
using python
File metadata and controls
38 lines (32 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# A single node of a singly linked list
class Node:
# constructor
def __init__(self, data=None, second=None):
self.data = data
self.next = second
# A Linked List class with a single head node
class LinkedList:
def __init__(self):
self.head = None
# insertion method for the linked list
def insert(self, data):
new_node = Node(data)
if self.head:
current = self.head
while current.next:
current = current.next
current.next = new_node
else:
self.head = new_node
# print method for the linked list
def print_ll(self):
current = self.head
while current:
print(current.data)
current = current.next
# Singly Linked List with insertion and print methods
LL = LinkedList()
LL.insert(7)
LL.insert(9)
LL.insert(6)
LL.print_ll()