Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
micro(A)v11
just to show something ...


Attached Files Image(s)
       
Reply
this one must looks better Big Grin 
Code: (Select All)
'create stack using array (...of integers) o2 by Aurel 13.1.2025
string crlf = chr(13) + chr(10), stbuff
int stack[16] ,size = 16
int top = 0
! push(int i)
! pop()  as int
! peek() as int

sub push(int a)
    if top = size - 1
       print "Stack is Overflow!" : goto exitProgram
    else
      top = top + 1      ' increment stack index
      stack[top] = a     ' enter value
    end if
end sub

sub pop()
    if top = 0
       print "Stack is Underflow!" : goto exitProgram
    else
      stack[top] = 0  ' remove curent value
      top = top - 1   ' decrement stack index
    end if 
end sub

sub printStack()
int i
    for i = 1 to top
        stbuff = stbuff + str(i) + " : " + str(stack[i]) + crlf
    next i
'show stack
print stbuff
end sub

'push some values on the stack
int v=1,x=10
while v < 11
   push(x)
   x = x + 10
   v=v+1
wend

'test 1......
printStack()

exitProgram:
print "EXIT..."

as img

as image ...


Attached Files Image(s)
   
Reply




Users browsing this thread: 3 Guest(s)