예제 #1
0
def biconnectivity(G):
    depth = [-1] * G.order
    cutPoints = [0] * G.order
    cutEdges = []
    comp = []
    st = stack.Stack()
    for x in range(G.order):
        if depth[x] == -1:
            depth[x] = 0
            nbChildren = 0
            for y in G.adjlists[x]:
                if depth[y] == -1:
                    nbChildren += 1
                    st.push((x, y))
                    depth[y] = 1
                    ph_y = __biconnectivity(G, y, x, depth, cutPoints,
                                            cutEdges, st, comp)
                    if ph_y > 0:  # depth[x]
                        cutEdges.append((x, y))
                    bc = []
                    while not st.isempty():
                        bc.append(st.pop())
                    comp.append(bc)
                cutPoints[x] += nbChildren - 1

    return (cutPoints, cutEdges, comp)
예제 #2
0
def topologicalOrder(G, src):
    '''
    make topological order of subgraph from vertices 
    that are reachable from src
    '''
    M = [False] * G.order
    order = stack.Stack()
    dfsSuff(G, src, M, order)
    return order
def Tarjan(G):
    pref = [0] * G.order
    cpt = 0
    vertexStack = stack.Stack()
    k = 0
    cfc = [0] * G.order
    for s in range(G.order):
        if pref[s] == 0:
            (_, cpt, k) = __Tarjan(G, s, pref, cpt, cfc, k, vertexStack)
    return (k, cfc )
예제 #4
0
def eval_rpn(L):
    """
    algo:
        init pile
        pour chaque élément e de L:
            si e est une valeur:
               l'empiler
            sinon #opérateur
                évaluation:
                  récupérer les 2 opérandes = dépiler
                  empiler le résultat de l'opération
    """
    p = stack.Stack()
    for e in L:
        #FIXME
        pass
def Kosaraju(G):
    post = stack.Stack()
    M = [False] * G.order
    for s in range(G.order):
        if not M[s]:
            __dfsPost(G, s, M, post)
    
    G_1 = reverseGraph(G)
    comp = [0]*G.order
    no = 0
    while not post.isEmpty():
        s = post.pop()
        if comp[s] == 0:
            no += 1
            __dfs(G_1, s, comp, no)
    
    return (no, comp)
예제 #6
0
# -*- coding: utf-8 -*-
"""
Sept. 2019
@author: nathalie
S2# tutorial: to see how to use stacks
"""

from algopy import stack

# a new stack
p = stack.Stack()

# all operation are implemented as method!

# stack.push (empiler)
p.push(1)
p.push(2)
p.push(3)

# stack.peek (sommet)
print(p.peek())

# stack.pop (sommet + dépiler)
print(p.pop())
print(p.peek())

# stack.isempty (est-vide)
print(p.isempty())
p.pop()
p.pop()
print(p.isempty())