-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject_StackQueueLinkedList.java
175 lines (167 loc) · 5.52 KB
/
Project_StackQueueLinkedList.java
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package project_stackqueuelinkedlist;
import java.util.Random;
import java.util.Scanner;
/**
*
* @author hannahgsimon
*/
public class Project_StackQueueLinkedList
{
public static void main(String[] args)
{
Project_StackQueueLinkedList proj = new Project_StackQueueLinkedList();
proj.run();
}
public void run()
{
StackArray<SampleData> saData = new StackArray<>();
StackList<SampleData> slData = new StackList<>();
QueueArray<SampleData> qaData = new QueueArray<>();
QueueList<SampleData> qlData = new QueueList<>();
int sel = 0;
Random rand = new Random();
Scanner input = new Scanner(System.in);
while(true)
{
System.out.println("1)\tAuthor Info\n2)\tAdd Stack Array Data\n3)\tAdd Stack List Data\n4)\tAdd Queue Array Data\n5)\tAdd Queue List Data\n6)\tRemove Stack Array Data\n7)\tRemove Stack List Data\n8)\tRemove Queue Array Data\n9)\tRemove Queue List Data\n10)\tGet Max Pending Data\n11)\tPrint Data\n0)\tExit");
sel = getInt(input);
if (sel == 0)
{
break;
}
else if (sel == 1)
{
sel = rand.nextInt();
if (sel % 4 == 0)
{
System.out.println(saData.getAuthorInfo());
}
else if (sel % 4 == 1)
{
System.out.println(slData.getAuthorInfo());
}
else if (sel % 4 == 2)
{
System.out.println(qaData.getAuthorInfo());
}
else if (sel % 4 == 3)
{
System.out.println(qlData.getAuthorInfo());
}
}
else if (sel == 2)
{
System.out.println("Enter data");
sel = getInt(input);
SampleData data = new SampleData(sel);
saData.push(data);
}
else if (sel == 3)
{
System.out.println("Enter data");
sel = getInt(input);
SampleData data = new SampleData(sel);
slData.push(data);
}
else if (sel == 4)
{
System.out.println("Enter data");
sel = getInt(input);
SampleData data = new SampleData(sel);
qaData.enque(data);
}
else if (sel == 5)
{
System.out.println("Enter data");
sel = getInt(input);
SampleData data = new SampleData(sel);
qlData.enque(data);
}
else if (sel == 6)
{
if (saData.hasData())
{
System.out.printf("Removing %s from Stack\n", saData.pop());
}
else
{
System.out.println("Storage Empty");
}
}
else if (sel == 7)
{
if (slData.hasData())
{
System.out.printf("Removing %s from Stack\n", slData.pop());
}
else
{
System.out.println("Storage Empty");
}
}
else if (sel == 8)
{
if (qaData.hasData())
{
System.out.printf("Removing %s from Queue\n", qaData.dequeue());
}
else
{
System.out.println("Storage Empty");
}
}
else if (sel == 9)
{
if (qlData.hasData())
{
System.out.printf("Removing %s from Queue\n", qlData.dequeue());
}
else
{
System.out.println("Storage Empty");
}
}
else if (sel == 10)
{
SampleData max = saData.peek();
if (slData.compareTo(max) > 0)
{
max = slData.peek();
}
if (qaData.compareTo(max) > 0)
{
max = qaData.peek();
}
if (qlData.compareTo(max) > 0)
{
max = qlData.peek();
}
System.out.printf("The largest pending value is: %s\n", max);
}
else if (sel == 11)
{
System.out.println("Stack Array: " + saData);
//System.out.println("head: " + saData.head);
System.out.println("Stack List: " + slData);
System.out.println("Queue Array: " + qaData);
//System.out.println("head: " + qaData.head +"\ntail: " + qaData.tail);
System.out.println("Queue List: " + qlData);
}
}
}
public int getInt(Scanner input)
{
while(true)
{
if (input.hasNextInt())
{
return(input.nextInt());
}
else
{
input.next();
System.out.println("\nInvalid Selection\n");
}
}
}
}