-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStackTest.java
More file actions
52 lines (47 loc) · 1.11 KB
/
Copy pathStackTest.java
File metadata and controls
52 lines (47 loc) · 1.11 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
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class StackTest
{
private StackLL<String> stack;
private Scanner sc;
public StackTest()
{
try
{
this.sc = new Scanner(new File("stack_data.txt"));
}
catch (FileNotFoundException e)
{
this.sc = new Scanner(System.in);
}
stack = new StackLL<String>();
}
public void test()
{
while (sc.hasNext())
{
String str = sc.next();
if (str.equals("-"))
System.out.println(">>> " + stack.pop());
else
stack.push(str);
}
}
public void testIteration()
{
while (sc.hasNext())
{
String str = sc.next();
stack.push(str);
}
System.out.println("Iterating...");
for (String item : stack)
System.out.println("-> " + item);
}
public static void main(String[] args)
{
StackTest stest = new StackTest();
stest.testIteration();
}
}