forked from rushilp002/beachHacks2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.py
40 lines (31 loc) · 818 Bytes
/
LinkedList.py
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
import numpy as np
#LinkedList is a data structure
class LinkedList:
class Node:
def __init__(self, data):
self.next = None
self.data = data
def __init__(self):
self.head = None
self.tail = None
self.n = 0
def push(self, data):
u = self.Node(data)
u.next = self.head
self.head = u
if self.n == 0:
self.tail = u
self.n += 1
return data
def pop(self) -> np.object:
try:
data = self.head.data
self.head = self.head.next
self.n -= 1
if self.n == 0:
self.tail = None
return data
except:
raise IndexError()
def size(self) -> int:
return self.n