@agscomputing/

AdvancedEntireTechnology

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class MyStack2(object):
    def __init__(self, limit = 10):
        self.stk = limit * [None]
        self.limit = limit

    def is_empty(self):
        return len(self.stk) <= 0

    def push(self,item):
        if len(self.stk) >= self.limit:
            self.resize()
        self.stk.append(item)
        print("Stack after push", self.stk)

    def pop(self):
        if len(self.stk) <= 0:
            print("Stack Underflow")
            return 0
        else:
            return self.stk.pop()

    def peek(self):
        if len(self.stk) <= 0:
            print("Stack Underflow")
            return 0
        else:
            return self.stk[-1]

    def size(self):
        return len(self.stk)

    def resize(self):
        newStk = list(self.stk)
        self.limit = 2 * self.limit
        self.stk = newStk

def main():
    our_stack = MyStack2(0)
    our_stack.push("1")
    our_stack.push("21")
    our_stack.push("14")
    our_stack.push("11")
    our_stack.push("31")
    our_stack.push("14")
    our_stack.push("15")
    our_stack.push("19")
    our_stack.push("3")
    our_stack.push("99")
    our_stack.push("9")
    print (our_stack.peek())
    print (our_stack.pop())
    print (our_stack.peek())
    print (our_stack.pop())
    pass

main()