示例#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)
示例#2
0
 def __dfsFromVertex(self, vertex: V, visited: Set[V],
                     stack: Stack) -> None:
     if vertex is None or visited is None or stack is None:
         raise Exception(
             "Invalid input: vertex: {}, visited: {}, stack: {}".format(
                 vertex, visited, stack))
     for neighbor, _ in self.__adjacencyMatrix.allSuccessors(vertex):
         if neighbor in visited:
             continue
         visited.add(neighbor)
         self.__dfsFromVertex(neighbor, visited, stack)
     stack.push(vertex)
示例#3
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")
示例#4
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
示例#5
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")
示例#7
0
#! /usr/local/bin/python
from common import table
from common import Stack
import sys
task2=table(sys.argv[1])
mx=task2.construct()
#stk=Stack()
#stk.push('S $')

for line in open(sys.argv[2],'rU'):
	trig=0
	stk=Stack()
	stk.push('S $')
	print '***',stk.prt()
	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'
示例#8
0
class StackTest(unittest.TestCase):
    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)

    def testPop(self) -> None:
        self.assertIn(5, self.__stack.pop())
        self.assertEqual(4, len(self.__stack))

    def testPush(self) -> None:
        self.__stack.push(6)
        self.assertIn(6, self.__stack.pop())
        self.assertEqual(5, len(self.__stack))

    def testFindKey(self) -> None:
        self.assertTrue(self.__stack.findKey(1))
        self.assertFalse(self.__stack.findKey(999999))

    def testPushEmptyKey(self) -> None:
        with self.assertRaises(Exception):
            self.__stack.push(None)

    def testPopAll(self) -> None:
        for _ in range(6):
            item = self.__stack.pop()
        self.assertTrue(not item)
示例#9
0
#! /usr/local/bin/python
from common import Stack
ss = Stack()
ss.push('abc')
ss.push('def')

print ss.prt()
示例#10
0
文件: test.py 项目: mtswiss/UniWork
#! /usr/local/bin/python
from common import Stack
ss=Stack()
ss.push('abc')
ss.push('def')


print ss.prt()