MCPcopy Create free account
hub / github.com/Seogeurim/CS-study / main

Method main

contents/data-structure/code/Stack/StackExample.java:5–62  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

3public class StackExample {
4
5 public static void main(String[] args) {
6 {
7 ArrayStack<Integer> stack = new ArrayStack<>();
8
9 stack.push(5);
10 stack.push(3);
11
12 System.out.println(stack.size()); // 2
13 System.out.println(stack.pop()); // 3
14 System.out.println(stack.isEmpty()); // false
15 System.out.println(stack.pop()); // 5
16 System.out.println(stack.isEmpty()); // true
17 System.out.println(stack.pop()); // null
18
19 stack.push(7);
20 stack.push(9);
21
22 System.out.println(stack.peek()); // 9
23
24 stack.push(4);
25
26 System.out.println(stack.size()); // 3
27 System.out.println(stack.pop()); // 4
28
29 stack.push(6);
30 stack.push(8);
31
32 System.out.println(stack.pop()); // 8
33 }
34 {
35 LinkedStack<Integer> stack = new LinkedStack<>();
36
37 stack.push(5);
38 stack.push(3);
39
40 System.out.println(stack.size()); // 2
41 System.out.println(stack.pop()); // 3
42 System.out.println(stack.isEmpty()); // false
43 System.out.println(stack.pop()); // 5
44 System.out.println(stack.isEmpty()); // true
45 System.out.println(stack.pop()); // null
46
47 stack.push(7);
48 stack.push(9);
49
50 System.out.println(stack.peek()); // 9
51
52 stack.push(4);
53
54 System.out.println(stack.size()); // 3
55 System.out.println(stack.pop()); // 4
56
57 stack.push(6);
58 stack.push(8);
59
60 System.out.println(stack.pop()); // 8
61 }
62 }

Callers

nothing calls this directly

Calls 5

pushMethod · 0.95
sizeMethod · 0.95
popMethod · 0.95
isEmptyMethod · 0.95
peekMethod · 0.95

Tested by

no test coverage detected