class Node: def __init__(self,data,prev,nxt): self.data = data self.prev = prev self.nxt = nxt class MyStack: def __init__(self): self.head = None self.count = 0 def push(self,data): n = new Node(data,None,self.head) self.head.prev = n self.head = n self.count += 1 def pop(self): if self.count == 0: raise(Exception) temp = self.head self.head = self.head.nxt self.head.prev = None return temp.data def getSize(self): return self.count def peek(self): if self.count == 0: raise(Exception) return self.head.data def is_empty(self): if self.count == 0: return True else : return False def main(): stack = new MyStack() for i in range(10): push(i) print stack.peek() print stack.getSize() print stack.pop() main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question