-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathll2.py
More file actions
66 lines (54 loc) · 1.58 KB
/
Copy pathll2.py
File metadata and controls
66 lines (54 loc) · 1.58 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class Node:
def __init__(self,data=None,next=None):
self.data=data
self.next=next
class single():
def __init__(self):
self.head=None
def __repr__(self):#repr is a represnting the list i.e traversal of the linked list
pass
def __contains__(self):#contains is used to check that the value contains in the linked list
pass
def __len__(self):
pass
#O(n) linear time complexity because to append we want to go through all the list
def append(self,value):
if self.head is None:
self.head= Node(value)
else:
last=self.head
while last.next:
last=last.next
last.next=Node(value)
#0(1)-constant time complexity beacuse i am gonna add only in the head node which is frist and best case
def prepend(self,value):
first_node=Node(value)
first_node.next=self.head
self.head=first_node
def insert(self,value,index):
if index == 0:
self.prepend(value)
else:
if self.head is None:
raise ValueError("Index out of bounce")
else:
pass
def delete(self,value):
pass
def pop(self,index):
pass
def get(self,index):
pass
def print(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None")
if __name__=="__main__":
s=single()
s.append(2)
s.append(3)
s.print()
s.prepend(4)
s.print()