Skip to content

Array-based stack

Java push / pop

Flowchart (ISO 5807)

StartInput xdata[top] = xtop = top + 1EndFigure 1 — Stack.pushStarttop = top − 1Return data[top]EndFigure 2 — Stack.pop

Source code

Java
class Stack {
    int[] data = new int[100];
    int top = 0;

    void push(int x) {
        data[top] = x;
        top++;
    }

    int pop() {
        top--;
        return data[top];
    }
}

The editor opens with this code — change it and the chart redraws.

Language
Java
Constructs
push / pop
Topic
Classes & methods
Formats
Word, Visio, draw.io, PDF, SVG

Related examples