def test_transfer():
    S = ArrayStack()
    S.push(3)
    S.push(2)
    S.push(1)
    print(S)
    T = ArrayStack()
    transfer(S, T)
    print(T)
Beispiel #2
0
 def test_pop(self):
     s = ArrayStack()
     s.push(1)
     self.assertEqual(s.pop(), 1)
     s.push(2)
     s.push(3)
     s.pop()
     self.assertEqual(s.top(), 2)
def test_stack_clear():
    S = ArrayStack()
    S.push(3)
    S.push(2)
    S.push(1)
    print(S)
    stack_clear(S)
    print(S)
def test_reverse_stack():
    S = ArrayStack()
    S.push(3)
    S.push(2)
    S.push(1)
    print(S)
    reverse_stack(S)
    print(S)
def test_three_stack():
    R = ArrayStack()
    R.push(1)
    R.push(2)
    R.push(3)

    S = ArrayStack()
    S.push(4)
    S.push(5)

    T = ArrayStack()
    T.push(6)
    T.push(7)
    T.push(8)
    T.push(9)

    three_stack(R, S, T)
    print("R:")
    print(R)
    print("S:")
    print(S)
def reverse_list(items):
    s = ArrayStack()
    for item in items:
        s.push(item)
    for i in range(len(items)):
        items[i] = s.pop()
def reverse_stack(S: ArrayStack):
    s1 = ArrayStack()
    s2 = ArrayStack()
    transfer(S, s1)
    transfer(s1, s2)
    transfer(s2, S)