Please include screenshot on submissions.
1) Design a queue abstract data type for float elements in Java, including operations for enqueue, dequeue,
and empty. The dequeue operation removes the element and returns its value.
2) Modify the Java class for the abstract stack type shown below to use a linked list representation and test it
with the same test code that appears below.
class StackClass {
private int[] stackRef;
private int maxLen, topIndex;
public StackClass() { // A constructor
stackRef = new int[100];
maxLen = 99;
topIndex = -1;
}
public void push(int number) {
if (topIndex == maxLen)
System.out.println("Error in push—stack is full");
else
stackRef[++topIndex] = number;
}
public void pop() {
if (empty())
System.out.println("Error in pop—stack is empty");
else
--topIndex;
}
public int top() {
if (empty()) {
System.out.println("Error in top—stack is empty");
return 9999;
} else return (stackRef[topIndex]);
}
public boolean empty() {
return (topIndex == -1);
}
}
public class TstStack {
public static void main(String[] args) {
StackClass myStack = new StackClass();
myStack.push(42);
myStack.push(29);
System.out.println("29 is: " + myStack.top());
myStack.pop();
System.out.println("42 is: " + myStack.top());
myStack.pop();
myStack.pop(); // Produces an error message
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
27 | 28 | 29 | 30 | 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 |