-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
61 lines (43 loc) · 1.08 KB
/
Copy pathStack.java
File metadata and controls
61 lines (43 loc) · 1.08 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
import java.util.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Stack {
//take all the functions from the Queue class
//and update them if necessary to function for a Stack
private static int size;
private static LinkedList<Integer> printQueue;
public void Push(int x){
//stick in the back of the linked list
size++;
printQueue.addFirst(x);
}
public int Pop(){
//Take out from the front of the linked list
if(size > 0){
size--;
return printQueue.removeFirst();
} else {
System.out.println("There are no more Jobs in Queue");
return 0;
}
}
public void Print(){
Iterator<Integer> i = printQueue.iterator();
System.out.println("Starting Queue");
while(i.hasNext()){
int temp = i.next();
System.out.println(temp);
}
System.out.println("Queue ended");
}
public static int GetSize(){
return size;
}
public Stack(){
size = 0;
printQueue = new LinkedList<Integer>();
}
LinkedList stack = new LinkedList();
}