예제 #1
0
def simple_balanced_parantheses(parantheses_string):
    # a stack as data structure is used
    stack = my_stack.Stack()

    # process the string of parantheses
    for elem in parantheses_string:
        if elem in "([{":
            stack.push(elem)
            # print(elem)

        # if the parentheses is a closing one, we have to chech
        # that we can get the last elem. added out of the stack
        # i.e. stack has at least one element
        # and it is the same type
        elif elem in ")]}":
            if not stack.isEmpty():
                if elem == ")" and stack.peek() == "(":
                    stack.pop()
                elif elem == "]" and stack.peek() == "[":
                    stack.pop()
                elif elem == "}" and stack.peek() == "{":
                    stack.pop()
                else:
                    return False
                # print(elem)
            else:
                return False  # can't pop from empty stack

    return stack.isEmpty()
예제 #2
0
def crt_stack(list_box, l, window):
    # Put the data in the queue
    if error_2(l, window) == 0:
        n = int(l)
        list_box.delete(0, END)
        i = 0
        m = n - 1

        global pilha
        pilha = my_stack.Stack()

        # Put the data in the stack
        for x in range(n):
            pilha.push(my_stack.Data_match(match, get_randoms(match)))

        while i < n:
            list_box.insert(i, (m, ":", my_stack.get(pilha, i).match_api_id))
            i += 1
            m -= 1
예제 #3
0
def is_parentheses_matched(expression):
    #( a + b ) / (a - b)
    parenthesesList = ['(', ')', '{', '}', '[', ']']

    s = mS.Stack()

    for char in expression:
        if (char in parenthesesList):
            if char == '(' or char == '{' or char == '[':
                s.push(char)
            else:
                if s.empty():
                    return False

                top = s.peek()
                if parenthesesList.index(top) + 1 == parenthesesList.index(
                        char):
                    s.pop()

    return s.empty()
예제 #4
0
import my_stack
import my_queue

stack = my_stack.Stack()
queue = my_queue.Queue()
for c in "Hello":
    stack.push(c)
    queue.enqueue(c)
reverse = ""
not_reverse = ""

while not stack.is_empty():
    reverse += stack.pop()

while not queue.is_empty():
    not_reverse += queue.dequeue()

print(reverse)
print(not_reverse)
예제 #5
0
#!/usr/bin/env python
# encoding: utf-8

import my_stack
s = my_stack.Stack(10)
for i in range(9):
    s.push(i)
s.show()
s.push(9)
s.show()
s.push(10)
s.pop()
s.show()
print(s.length())
print(s.get_top())
for i in range(9):
    s.pop()
s.pop()
print(s.get_top())
예제 #6
0
    #Return an aleatory int
    return random.randint(0, l)


#Get the data of the csv and put it in a dataframe of pandas library
match = pd.read_csv('match.csv')
country = pd.read_csv('country.csv')
league = pd.read_csv('league.csv')
player = pd.read_csv('player.csv')
player_attributes = pd.read_csv('player_attributes.csv')
team = pd.read_csv('team.csv')
team_attributes = pd.read_csv('team_attributes.csv')

#Creat the stack
pilha = my_stack.Stack()

#Put the data in the stack
for x in range(100):

    pilha.push(my_stack.Data_match(match, get_randoms(match)))

#Print 100 match_id from the stack
for x in range(pilha.getSize()):

    print(my_stack.get(pilha, x).match_api_id)

print(" ")

#print(my_stack.find_position(pilha,int(input("Digite um id: "))))