Exemplo n.º 1
0
 def setUp(self) -> None:
     self.__stack = Stack()
     self.__stack.push(1)
     self.__stack.push(2)
     self.__stack.push(3)
     self.__stack.push(4)
     self.__stack.push(5)
Exemplo n.º 2
0
 def dfs(self) -> Generator[V, None, None]:
     visited = set()
     stack: Stack = Stack()
     if self.__adjacencyMatrix.isDigraph():
         for vertex in self.__adjacencyMatrix.zeroInDegreeVertexes():
             if vertex in visited:
                 continue
             self.__dfsFromVertex(vertex, visited, stack)
             while (len(stack) > 0):
                 v, _ = stack.pop()
                 yield v
     else:
         raise Exception("This is not a Digraph")
Exemplo n.º 3
0
 def dfsFromVertex(self,
                   vertex: V,
                   visited: Set[V] = None) -> Generator[V, None, None]:
     if vertex is None:
         raise Exception("Vertex is None")
     if self.__adjacencyMatrix.checkVertexExist(vertex) is None:
         raise Exception("Node not exist in graph")
     if visited is None:
         visited = set()
     stack: Stack = Stack()
     visited.add(vertex)
     self.__dfsFromVertex(vertex, visited, stack)
     while len(stack) > 0:
         v, _ = stack.pop()
         yield v
Exemplo n.º 4
0
#! /usr/local/bin/python
from common import table
from common import Stack
import sys
task2 = table(sys.argv[1])
mx = task2.construct()

for line in open(sys.argv[2], 'rU'):
    trig = 0
    stk = Stack()
    stk.push('S $')
    #	print '***',stk.prt()
    #	line=line[:-1]
    line = line[:-1] + '$'
    #	line+='$'
    print '++', line
    index = 0
    a = line[index]
    while not stk.is_empty():
        print '--', stk.prt()
        #		print '||',a
        X = stk.top()
        if X.isupper():
            #			print 'run 1','|',X,'|',a,'|',mx.get(X,a)
            if mx.get(X, a) != -1 and mx.get(X, a) != None:
                print mx.get(X, a)
                stk.pop()
                stk.push(mx.get(X, a)[0])
            else:
                print 'reject 1'
                trig = 1
import subprocess
import os
from api import TreeHouseClient, TreeHouseAPI
from common import Cache, Stack
from video import VideoDownloader
import getpass

# TODO: this is still pretty horrible. Pls no judge me on dis file. I wus lazy

client = TreeHouseClient(TreeHouseAPI())
downloader = VideoDownloader(client)
cache = Cache()
back_stack = Stack()


def new_menu(title=None):
    subprocess.call("clear")
    if title:
        print("-------- " + title + " --------")


def print_opts(opts):
    print("commands")
    for opt in opts:
        print("- " + opt)
    print("----------------")


def pick_menu(choice):
    print("menu called")
    subprocess.call("clear")
Exemplo n.º 6
0
#! /usr/local/bin/python
from common import Stack
ss = Stack()
ss.push('abc')
ss.push('def')

print ss.prt()