-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
27 lines (22 loc) · 667 Bytes
/
Stack.py
File metadata and controls
27 lines (22 loc) · 667 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
'''
Implementation of Stack data structure using Linked List
'''
import LinkedList as LL
class Stack():
def __init__(self, top=None):
if top:
obj = LL.Element(top)
self.ll = LL.LinkedList(obj)
else:
self.ll = LL.LinkedList()
def push(self, new_element):
obj = LL.Element(new_element)
obj.next = self.ll.head
self.ll.head = obj
def pop(self):
# Removes the top element from the stack and returns it
temp = self.ll.head.value
self.ll.head = self.ll.head.next
return temp
def converttoList(self):
return self.ll.convertToList()[::-1]