repl.it
Python

No description

fork
loading
Files
  • main.py
main.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
class Stack:
  class Node:
    data = None
    pointer = None

  top_pointer = None

  def push(self,item):
    try:
      new_node = Stack.Node()
      new_node.data = item
      new_node.pointer = self.top_pointer
      self.top_pointer = new_node
      return True
    except:
      return False

  def pop(self):
    if self.top_pointer != None:
      popped = self.top_pointer.data
      self.top_pointer = self.top_pointer.pointer
      return popped
    else:
      return None

  def peek(self):
    if self.top_pointer != None:
      return self.top_pointer.data
    else:
      return None
items =["Florida","Georgia","Delware","Alabama","California"]
s = Stack()
for index in range(0,len(items)):
  s.push(items[index])
s.push("New York")
print(s.pop())
print(s.peek())


Fetching token
?