' Graph adjacency list: nodes, edges, degree, neighbors
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    DIM nodeId(1 TO 10) AS LONG
    DIM nodeLabel(1 TO 10) AS STRING
    DIM adj1(1 TO 10) AS LONG
    DIM adj2(1 TO 10) AS LONG
    DIM adj3(1 TO 10) AS LONG
    DIM adj4(1 TO 10) AS LONG
    DIM adj5(1 TO 10) AS LONG
    DIM adj6(1 TO 10) AS LONG
    DIM deg(1 TO 10) AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL ncount AS LONG

    PRINT "=== Graph Adjacency List ==="
    PRINT

    ncount = 6
    nodeId(1) = 1
    nodeLabel(1) = "Server A" + SPACE$(8)
    nodeId(2) = 2
    nodeLabel(2) = "Server B" + SPACE$(8)
    nodeId(3) = 3
    nodeLabel(3) = "Server C" + SPACE$(8)
    nodeId(4) = 4
    nodeLabel(4) = "Router 1" + SPACE$(8)
    nodeId(5) = 5
    nodeLabel(5) = "Router 2" + SPACE$(8)
    nodeId(6) = 6
    nodeLabel(6) = "Firewall" + SPACE$(8)

    FOR i = 1 TO ncount
        deg(i) = 0
    NEXT i

    deg(1) = deg(1) + 1
    adj1(deg(1)) = 2
    deg(2) = deg(2) + 1
    adj2(deg(2)) = 1
    deg(1) = deg(1) + 1
    adj1(deg(1)) = 4
    deg(4) = deg(4) + 1
    adj4(deg(4)) = 1
    deg(2) = deg(2) + 1
    adj2(deg(2)) = 3
    deg(3) = deg(3) + 1
    adj3(deg(3)) = 2
    deg(2) = deg(2) + 1
    adj2(deg(2)) = 4
    deg(4) = deg(4) + 1
    adj4(deg(4)) = 2
    deg(3) = deg(3) + 1
    adj3(deg(3)) = 5
    deg(5) = deg(5) + 1
    adj5(deg(5)) = 3
    deg(4) = deg(4) + 1
    adj4(deg(4)) = 5
    deg(5) = deg(5) + 1
    adj5(deg(5)) = 4
    deg(4) = deg(4) + 1
    adj4(deg(4)) = 6
    deg(6) = deg(6) + 1
    adj6(deg(6)) = 4
    deg(5) = deg(5) + 1
    adj5(deg(5)) = 6
    deg(6) = deg(6) + 1
    adj6(deg(6)) = 5

    PRINT "Network topology:"
    FOR i = 1 TO ncount
        PRINT "  " & FORMAT$(nodeId(i)) & " [" & TRIM$(nodeLabel(i)) & "] ->"
        FOR j = 1 TO deg(i)
            IF i = 1 THEN PRINT " " & FORMAT$(adj1(j))
            IF i = 2 THEN PRINT " " & FORMAT$(adj2(j))
            IF i = 3 THEN PRINT " " & FORMAT$(adj3(j))
            IF i = 4 THEN PRINT " " & FORMAT$(adj4(j))
            IF i = 5 THEN PRINT " " & FORMAT$(adj5(j))
            IF i = 6 THEN PRINT " " & FORMAT$(adj6(j))
        NEXT j
        PRINT " (deg:" & FORMAT$(deg(i)) & ")"
    NEXT i
    PRINT

    PRINT "Degree of node 2: " & FORMAT$(deg(2))
    PRINT "Degree of node 4: " & FORMAT$(deg(4))
    PRINT

    PRINT "Neighbors of node 4:"
    FOR j = 1 TO deg(4)
        PRINT " " & FORMAT$(adj4(j))
    NEXT j
    PRINT
    PRINT

    PRINT "Graph tests complete."
    FUNCTION = 0
END FUNCTION
