Page 292 - Learn to Program - Basic-256
P. 292

Chapter 19: Stacks, Queues, Lists, and Sorting                                  Page 276


             14     while not empty()
             15     print pop()
             16     end while
             17
             18     end
             19
             20     function empty()
             21     # return true if the start is empty
             22     return nstack=0
             23     end function
             24
             25     function pop()
             26     # get the top number from stack and return it
             27     # or print a message and return -1
             28     if nstack = 0 then
             29     print "stack empty"
             30     return -1
             31     end if
             32     nstack = nstack - 1
             33     value = stack[nstack]
             34     return value
             35     end function
             36
             37     subroutine push(value)
             38     # push the number in the variable value onto the
                    stack
             39     # make the stack larger if it is full
             40     if nstack = stack[?] then redim stack(stack[?] + 5)
             41     stack[nstack] = value
             42     nstack = nstack + 1
             43     end subroutine

        Program 116: Stack













                                                       © 2019 James M. Reneau (CC BY-NC-SA 3.0 US)
   287   288   289   290   291   292   293   294   295   296   297