예제 #1
0
def BFS(G,s):
    for u in G.getVertices():
        if u!=s:
            u.color='white'
            u.d=np.inf
            u.pre=None
    s.color='gray'
    s.d=0
    s.pre=None
    Q=Queue()
    Q.Enqueue(s)
    while not Q.IsEmpty():
        u=Q.Dequeue()
        for v in u.getConnections():
            if v.color=='white':
                v.color='gray'
                v.d=u.d+1
                v.pre=u
                Q.Enqueue(v)
        u.color='black'
예제 #2
0
from myqueue import Queue

myq = Queue()

myq.Enqueue('A')
myq.Enqueue('B')
myq.Enqueue('C')
myq.Enqueue('D')
myq.Enqueue('A')
myq.Enqueue('E')

myq.PrintQueue()

len_now = myq.queueNo


def deleteqA(item):

    i = 0
    while i < len_now:

        if myq.queue[myq.front + 1] != item:
            myq.Enqueue(myq.Dequeue())

        else:
            myq.Dequeue()

        i += 1


def deleteqA2(item):
예제 #3
0
from myqueue import Queue

myq = Queue()

myq.Enqueue('A')
myq.Enqueue('B')
myq.Enqueue('C')
myq.Enqueue('D')
myq.Enqueue('E')

myq.PrintQueue()
print("Elements in queue: ", myq.queueNo)  # Please check queue.py for details

myq.Dequeue()
myq.PrintQueue()
print("Elements in queue: ", myq.queueNo)  # Please check queue.py for details

myq.Enqueue('F')
myq.PrintQueue()
print("Elements in queue: ", myq.queueNo)  # Please check queue.py for details