-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from javatreble/javatreble-patch-1
ArrayList Implementation of Stack
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |