You are on page 1of 1

Array implementation of Stack

Operation Push
Method 1. begin
2. if top = n then stack full
3. top = top + 1
4. stack (top) : = item;
5. end

Time Complexity O(1)

Operation Pop
Method 1. begin
2. if top = 0 then stack empty;
3. item := stack(top);
4. top = top - 1;
5. end;

Time Complexity O(1)

Operation Peek
Method 1. Begin
2. if top = -1 then stack empty
3. item = stack[top]
4. return item
5. End

Time Complexity O(n)

You might also like