def __init__(self):

        self.stack = Stack()
        with open("json_file/Transaction_Stack.json") as data:
            try:
                temp = json.load(data)
            except Exception:
                pass
            else:
                for i in temp:
                    self.stack.push(i)
Beispiel #2
0
class PrimeWithStack:
    def __init__(self):

        self.stack = Stack()

    def prime_with_stack(self, rng):

        prime_number = get_prime_number(rng)
        anagram = get_anagram(prime_number)
        for i in anagram:
            self.stack.push(i)
        for i in range(self.stack.size()):
            print(self.stack.pop(), end=" ")
class CalendarWithStack:
    def __init__(self):

        self.stack1 = Stack()
        self.stack2 = Stack()

    def display(self, month, year):

        calendar = Calendar()
        print("------------", month, year, "---------------")
        for i in calendar.week:
            print(i, end="    ")
        for i in range(self.stack2.size()):
            temp = self.stack2.pop()
            if i % 7 == 0:
                print()
            if int(temp) == 0:
                print(end="     ")
            elif int(temp) < 10:
                print(temp, end="    ")
            else:
                print(temp, end="   ")

    def calendar_with_stack(self, month, year):

        queue = CalendarWithQueue()
        queue = queue.calendar_with_queue(month, year)
        for i in range(queue.size()):
            self.stack1.push(queue.dequeue())
        for i in range(self.stack1.size()):
            self.stack2.push(self.stack1.pop())
class TransactionStack:
    def __init__(self):

        self.stack = Stack()
        with open("json_file/Transaction_Stack.json") as data:
            try:
                temp = json.load(data)
            except Exception:
                pass
            else:
                for i in temp:
                    self.stack.push(i)

    def transaction_stack(self, transaction, customer_name, company_name,
                          no_of_share, cost, time):

        new_transaction = {
            "transaction": transaction,
            "customer_name": customer_name,
            "company_name": company_name,
            "no_of_share": no_of_share,
            "cost": cost,
            "time": time
        }
        self.stack.push(new_transaction)

    def save_transaction(self):

        temp1 = []
        size = self.stack.size()
        for i in range(size):
            temp1.append(self.stack.pop())
        with open("Transaction_stack.json", 'w') as data:
            json.dump(temp1, data)
class Balancedparentheses:
    def __init__(self):
        self.stack = Stack()

    def balancedparentheses(self, string):
        for i in string:
            if i is '(':
                self.stack.push(i)
            elif i is ')' and self.stack.peak() is '(':
                self.stack.pop()
        if self.stack.size() is 0:
            return True
        else:
            return False
    def __init__(self):

        self.stack1 = Stack()
        self.stack2 = Stack()
Beispiel #7
0
    def __init__(self):

        self.stack = Stack()