Two implementations
class Stack[T] {
private:
items:array[10] of T;
public:
push(item:T):void {
items[top] := item;
top := top + 1;
pop():T {
top := top - 1;
return items[top];
size():int {return top;}
class Stack[T] {
private:
items:list[T] := nil;
public:
push(item:T):void {
items.add_first(item);
pop():T {
return items.remove_first();
size():int {return
items.length();
}
Instance variable
Method implementation
Previous slide
Next slide
Back to first slide
View graphic version