-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluePrint(nodes).java
More file actions
70 lines (60 loc) · 1.93 KB
/
bluePrint(nodes).java
File metadata and controls
70 lines (60 loc) · 1.93 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package nodePrac;
public class stackList {
// define sa una ang stackNode
private class stackNode{
String data;
stackNode tail;
//constructor dayun
public stackNode(String data){
this.data = data;
this.tail = tail;
}
}
private stackNode top;
private int counter;
public stackList(){
top = null;
counter = 0;
}
private boolean isEmpty(){
return counter == 0;
}
public boolean push(String data){
stackNode node = new stackNode(data);
node.tail = top;// reference ni para mo Point the new node's tail to the current top
top = node;// para mo Update top to be the new node
counter ++;// increment
return true;
}
public boolean pop(){
if (!isEmpty()) { // kong dili siya empty
top = top.tail;// para ma move ang top sa item na ubos niya
counter --;// decrement
return true; // if ni meet sa condition then true
}else{
return false; //kong wala false
}
}
public String peek(){
if (!isEmpty()) {//mo get siya sa top kong nay sud
return top.data;// gi return ang value sa top
}else{
return null; // return null(way sud) kong wala
}
}
public int getCounter(){
return counter;// return ra counter lahos
}
public void display(){
if (!isEmpty()) {// mo display basta dili empty
stackNode temp = top;// para mo start tas top
while (temp != null) {// while loop to go through items
System.out.println(temp.data);//para ma print ang value sa mga item;
temp = temp.tail;// para ma move to the next item
}
System.out.println();// wala rani
}else{
System.out.println(" Stack is Empty!");// mo display kong walay sud
}
}
}