System Stack

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
I've had the use for a stack several times so now when the modules was released I created one that's easy to use and works well because I needed it :p

JASS:
library Stack
    // This is a basic module for creating stacks.
    // To add something to the top of the stack us <struct var>.push(data)
    // and to retrieve the last added item use <struct var>.pop()
    // If you want to clean all datas added to the stack then use <struct var>.reset() 
    //
    // This stack works like this: Last in first out, this can easily be showed with this example
    //    call .push(1)
    //    call .push(2)
    //    call .push(3)
    //
    //    call BJDebugMsg(I2S(.pop()))
    //    call BJDebugMsg(I2S(.pop()))
    //    call BJDebugMsg(I2S(.pop()))

    // That piece of code will display 3, 2, 1 because of the way a stack is created.
module Stack  
    private static integer ERROR_RETURN = -8784574 // Just using something random if you want to check if 
                                                   // it reterned an error since you tried to pop too many datas
    
    private static integer array DATAS[8190]
    private static integer N = 0
    
    method push takes integer data returns nothing
        set .DATAS[.N] = data
        set .N = .N + 1
    endmethod
    
    method pop takes nothing returns integer
        if .N > 0 then
            set .N = .N - 1
            return .DATAS[.N]
        endif
        return .ERROR_RETURN
    endmethod
    
    method reset takes nothing returns nothing
        local integer i = .N
        loop
            exitwhen i < 0
            set .DATAS<i> = 0
            set i = i - 1
        endloop
        set .N = 0
    endmethod
endmodule
endlibrary</i>
 

Romek

Super Moderator
Reaction score
963
> I've had the use for a stuck several times
I've been wanting a stuck too.

This seems quite useful. :)
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
My internet is incredibly slow so I haven't been able to change it.. I tried but failed :p

You could do it for me! :O
 

Romek

Super Moderator
Reaction score
963
So, why would someone want to use this?
How do you use it?

Information! :)
If you can't edit a post, post it in a new post, and I'll merge the information.

> You could do it for me! :O
Done.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top