' Stack (LIFO) and Queue (FIFO) with array-based implementations
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    DIM st(1 TO 10) AS LONG
    DIM q(1 TO 10) AS LONG
    LOCAL top AS LONG
    LOCAL qh AS LONG
    LOCAL qt AS LONG
    LOCAL i AS LONG
    LOCAL v AS LONG

    PRINT "=== Stack and Queue ==="
    PRINT

    top = 0
    top = top + 1
    st(top) = 10
    top = top + 1
    st(top) = 20
    top = top + 1
    st(top) = 30
    top = top + 1
    st(top) = 40
    top = top + 1
    st(top) = 50
    PRINT "Stack after 5 pushes (top=" & FORMAT$(top) & "):"
    FOR i = top TO 1 STEP -1
        PRINT "  " & FORMAT$(st(i))
    NEXT i
    PRINT

    v = st(top)
    top = top - 1
    PRINT "Pop: " & FORMAT$(v)
    v = st(top)
    top = top - 1
    PRINT "Pop: " & FORMAT$(v)
    PRINT "Stack top now: " & FORMAT$(top)
    PRINT

    qh = 0
    qt = 0
    qt = qt + 1
    q(qt) = 100
    qt = qt + 1
    q(qt) = 200
    qt = qt + 1
    q(qt) = 300
    qt = qt + 1
    q(qt) = 400
    qt = qt + 1
    q(qt) = 500
    PRINT "Queue after 5 enqueues (head=" & FORMAT$(qh + 1) & " tail=" & FORMAT$(qt) & "):"
    FOR i = qh + 1 TO qt
        PRINT "  " & FORMAT$(q(i))
    NEXT i
    PRINT

    qh = qh + 1
    v = q(qh)
    PRINT "Dequeue: " & FORMAT$(v)
    qh = qh + 1
    v = q(qh)
    PRINT "Dequeue: " & FORMAT$(v)
    PRINT "Queue head now: " & FORMAT$(qh + 1)
    PRINT

    PRINT "Stack and queue tests complete."
    FUNCTION = 0
END FUNCTION
