-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharstack.java
More file actions
61 lines (50 loc) · 1.48 KB
/
Charstack.java
File metadata and controls
61 lines (50 loc) · 1.48 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
package stacksonstacks;
import java.util.LinkedList;
import java.util.*;
public class Charstack {
//static LinkedList <Character> stuff = new LinkedList<Character>();
static ArrayList <Character> stuff = new ArrayList<Character>();
static Scanner scnr = new Scanner(System.in);
public static void insert(String x) {
x = scnr.nextLine();
char chars = x.charAt(0);
stuff.add(chars);
}
public static char past() {
//see last input, something that shows the index and prompts the input of the one before
//char last = stuff.getLast();
char last = stuff.get(stuff.size()-1);
return last;
}
public static char peektop() {
//to show the top of the list or the last input made
//char top = stuff.getFirst();
char top = stuff.get(0);
return top;
}
public static boolean checkyes() {
boolean yes = stuff.isEmpty();
return yes;
}
public static void main (String[]arg) {
if (checkyes()== true) {
System.out.println("Stack is currently empty. Please enter 5 character class entries: ");
}
else {
System.out.println("Stack is currently not empty.");
}
insert(null);
insert(null);
insert(null);
insert(null);
insert(null);
System.out.println(past());
System.out.println(peektop());
if (checkyes()== true) {
System.out.println("Stack is currently empty.Entries did not work.");
}
else {
System.out.println("Stack is currently not empty. Entry sucessful!");
}
}
}