Skip to content

Instantly share code, notes, and snippets.

@GypsyDangerous
Last active April 17, 2019 21:42
Show Gist options
  • Save GypsyDangerous/d06e80235fa9694100e585133826bdd7 to your computer and use it in GitHub Desktop.
Save GypsyDangerous/d06e80235fa9694100e585133826bdd7 to your computer and use it in GitHub Desktop.
class stack:
def __init__(self, data=None):
self.data = []
if isinstance(data, list):
self.data.extend(data)
elif not data is None:
self.data.append(data)
def push(self, data):
self.data.append(data)
def pop(self):
return(self.data.pop())
def size(self):
return len(self.data)
def peek(self);
return self.data[-1]
def TIM(self):
self.push(self.pop()**2)
def SUM(self):
self.push(self.pop()*2)
class Queue:
def __init__(self, vals=None):
self.data = []
if isinstance(vals, list):
self.data.extend(vals)
elif not val is None:
self.data.append(vals)
def enqueue(self, val):
if isinstance(val, list):
for v in val:
self.data.insert(0, v)
else
self.data.insert(0, val)
def dequeue(self):
if self.size() == 0:
raise Exception("Queue empty")
return self.data.pop()
def Print(self):
for d in self.data:
print(d)
def size(self):
return len(self.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment