MCPcopy Create free account
hub / github.com/apna-college/Alpha / Stack

Class Stack

13_Stacks/StackLL.java:13–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 }
12
13 static class Stack {
14 public static Node head = null;
15 public static void push(int data) {
16 Node newNode = new Node(data);
17
18 if(head == null) {
19 head = newNode;
20 return;
21 }
22 newNode.next = head;
23 head = newNode;
24 }
25
26 public static boolean isEmpty() {
27 return head == null;
28 }
29
30 public static int pop() {
31 if(isEmpty()) {
32 return -1;
33 }
34 Node top = head;
35 head = head.next;
36 return top.data;
37 }
38
39 public static int peek() {
40 if(isEmpty()) {
41 return -1;
42 }
43 Node top = head;
44 return top.data;
45 }
46 }
47
48 public static void main(String args[]) {
49 Stack stack = new Stack();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…