Matlab - Stack Data Structure

后端 未结 5 1899
悲哀的现实
悲哀的现实 2021-02-07 22:39

Can I have a stack data structure in matlab?

For example a stack of integers where I can push elements in it like stack.push(i), get elements out of it like

5条回答
  •  清歌不尽
    2021-02-07 23:41

    I have used the Java one in MATLAB and honestly it is very slow. It's much better to do what @skurmedel said, like so:

    Ptr = 1;
    Stack(ptr,:) = [x,y];
    Ptr = ptr + 1;
    

    And to simulate pop:

    A = stack(ptr,1);
    B = stack(ptr,2);
    Ptr = ptr - 1;
    

提交回复
热议问题