Skip to content

Commit

Permalink
Merge pull request #1 from javatreble/javatreble-patch-1
Browse files Browse the repository at this point in the history
ArrayList Implementation of Stack
  • Loading branch information
javatreble authored Jul 25, 2017
2 parents 600e65f + 6b34ffd commit 479c99c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Chapter_24/inventory/InventoryStack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package test.stacks.queues;

import java.util.ArrayList;

public class InventoryStack<Inventory> {
private ArrayList<Inventory> list = new ArrayList<>();

public int getSize() {
return list.size();
}

public Inventory peek() {
return list.get(getSize() - 1);
}

public void push(Inventory o) {
list.add(o);
}

public boolean isEmpty() {
return list.isEmpty();
}


public Inventory pop() {
Inventory o = list.get(getSize() - 1);
list.remove(getSize() - 1);
return o;
}


@Override
public String toString(){

return"Inventory Stack Implementation using ArrayList: "+list.toString();

}
}

0 comments on commit 479c99c

Please sign in to comment.