Esempio n. 1
0
def infix_to_rpn(input_data):
    stack = Stack()
    temp = ""
    output = []
    dictionary = {'^': 3, '*': 2, '/': 2, '+': 1, '-': 1, '(': 0}
    for item in input_data:
        for char in item:
            if char in dictionary and char != '(':
                if stack.isEmpty():
                    stack.Push(char)
                elif dictionary.get(char) <= dictionary.get(stack.Top()):
                    temp += stack.Top()
                    stack.Pop()
                    stack.Push(char)
                elif dictionary.get(char) > dictionary.get(stack.Top()):
                    stack.Push(char)
            elif char == '(':
                stack.Push(char)
            elif char == ')':
                temp = clear_stack(stack, temp)
            elif char == '=':
                temp = clear_stack(stack, temp)
                output.append(temp)
                temp = ""
            else:
                temp += char
    return output
Esempio n. 2
0
 def test_StackSize(self):
     expectedResult = 3
     testStack = Stack()
     testStack.Push(1)
     testStack.Push(2)
     testStack.Push(3)
     testResult = testStack.Size()
     self.assertEqual(testResult, expectedResult)
Esempio n. 3
0
 def test_Push_Pop_Stack(self):
     expectedResult = 3
     testStack = Stack()
     testStack.Push(1)
     testStack.Push(2)
     testStack.Push(3)
     testResult = testStack.Pop()
     self.assertEqual(testResult, expectedResult)
Esempio n. 4
0
def main():
    s = Stack()
    print('Empty?: %s' % s.IsEmpty())
    s.Push('Dazed and Confused')
    s.Push('I Can\'t Quit You Baby')
    s.Push('Wearing and Tearing')
    print(s.Peek())
    print(s.Peek())
    print('Size: %s' % s.Size())
    s.Pop()

    print('Size: %s' % s.Size())
Esempio n. 5
0
def delete_last_10():
    blogPosts = BlogPost.query.all()

    s = Stack()

    for post in blogPosts:
        s.Push(post)

    for _ in range(10):
        postToDel = s.Pop()
        db.session.delete(postToDel.data)
        db.session.commit()

    return jsonify({"message":
                    "successfully deleted the last 10 blog posts"}), 200
Esempio n. 6
0
#-----------------------------------------------------------#
#   Title:      main.py                                     #
#   Author:     Drake G. Cummings                           #
#   Date:       January 22nd, 2021                          #
#   Purpose:    Driver file for linear data structures      #
#-----------------------------------------------------------#

from Stack import Stack
from Queue import Queue


#--------------------STACK METHODS--------------------#
testStack = Stack()
# .Push()
testStack.Push(5)
print(testStack.items)
testStack.Push(76)
print(testStack.items)

# .Pop()
print(testStack.Pop())

# .Contains()
print(testStack.Contains(5))
print(testStack.Contains(76))
print()


#--------------------QUEUE METHODS--------------------#
testQueue = Queue()
# .Append()
Esempio n. 7
0
from Stack import Stack

The_Stack = Stack()

The_Stack.Push('Hello')
The_Stack.Push('World')
The_Stack.Push('Hady')

print(The_Stack.Top())

print(The_Stack.Pop())
print(The_Stack.Pop())
print(The_Stack.Pop())
Esempio n. 8
0
from Stack import Stack

myStack = Stack()

while True:
    print('push <value>')
    print('pop')
    print('quit')
    do = input('What would you like to do?').split()

    operation = do[0].strip().lower()
    if operation == 'push':
        myStack.Push(int(do[1]))
    elif operation == 'pop':
        popped = myStack.Pop()
        if popped is None:
            print('Stack is empty.')
        else:
            print('Popped value: ', int(popped))
    elif operation == 'quit':
        break
Esempio n. 9
0
a = """
1. PUSH
2. POP
3. TOP
4. EMPTY
5. Max"""

choice = "Yes"

while choice:
    print(a)
    b = int(input('Enter your choice: '))
    if b == 1:
        c = int(input('Enter the element you want to push: '))
        stack.Push(c)
        print(stack.display())

    elif b == 2:
        if stack.Empty():
            print('Stack is empty')
        else:
            print('Popped element {} from the stack {}'.format(
                stack.Pop(), stack.display()))

    elif b == 3:
        print("The top element in the stack is {}", stack.Top())

    elif b == 4:
        if not stack.Empty():
            print('Stack is not empty')
from Stack import Stack
from Queue import Queue

#Calling Stack and Queue
testStack = Stack()
testQueue = Queue()

#Using push function to create a new list of words
testStack.Push("Beenus")
testStack.Push("Weenus")
testStack.Push("Freenus")

#Using append function to create a new list of words
testQueue.Append("Rat")
testQueue.Append("Snack")
testQueue.Append("Borlap")

#Testing if the Pop funciton works,
# Checking whats in the lest,
# Checking if list contains item that was popped,
# Checking if list contains item that was not popped,
# Checking if list contains item that never existed within it
print('Stack Test')
print(testStack.Pop())
print(testStack.items)
print(testStack.Contains('Beenus'))
print(testStack.Contains('Freenus'))
print(testStack.Contains('Wack'))

print('')