-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStackArray.java
More file actions
25 lines (16 loc) · 871 Bytes
/
MyStackArray.java
File metadata and controls
25 lines (16 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package Stack;
public class MyStackArray {
public static void main(String[] args) {
// Stack implemented with an array is perfect if you know how many items you need, otherwise it will be O(n)
// because you will have to resize the array then copy over the items to the new array to be able to add
// more items. Besides that, it is O(1) because you only add and remove items from the top of the stack
StackArray stack = new StackArray(4);
stack.push(new Employee("Jane", "Jones", 122));
stack.push(new Employee("Doug", "Jhonson", 288));
stack.push(new Employee("Leo", "Noronha Santos", 2553));
stack.printStack();
System.out.println("First item added to the stack: \n" + stack.peek());
System.out.println("Popped item is:\n" + stack.pop());
stack.printStack();
}
}