Question
//stack public class Stack { private Node top = null; private int size = 0; public boolean isEmpty() { return (top ==null); } public Object
//stack
public class Stack {
private Node top = null;
private int size = 0;
public boolean isEmpty() {
return (top ==null);
}
public Object top() {
return top.ob;
}
public void push (Object element) {
Node tmp = new Node (element);
tmp.Next=top;
top=tmp;
size++;
}
public Object pop() {
Node tmp = top;
top = top.Next;
size--;
return (Token)tmp.ob;
}
}
//Queue
public class Queue {
private int rear = -1;
private int front = 0;
private int size = 1024;
private Object s [] = new Object[size];
public boolean isEmpty() {
return front == (rear+1) % size;
}
public void enqueue (Object Element) {
rear = (rear+1) % size;
s[rear] = Element;
}
public Object dequeue() {
Object Element = s[front];
s[front] = null;
front = (front +1) % size;
return Element;
}
public String toString() {
String temp = "";
for (int i = 0; i
if (s[i]!=null) {
temp += s[i].toString() + " ";
}
}
return temp;
}
}
The Java class library: The Java Class Library is a set of dynamically loadable libraries that Java application programs can call at runtime. Like other standard code libraries, Java class library provides the programmer a well-known set of functions to perform common tasks, such as maintaining lists of items or performing complex string parsing. For Java 1.5 or later, some generic classes and generic interfaces are included in the Java class library. Examples import java.util.*; public class Stack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started