我正在做家庭作业,但我觉得我完全迷路了。这个家庭作业的重点是使用节点循环遍历堆栈和队列,但我认为我做得不对。在我当前的代码中,我没有任何东西去节点类,我确定我应该有东西去那里。我刚刚开始研究 main,测试功能和东西。
车类
public class Car {
String plate;
char code;
public Car(String plate, char code){
}
public String getPlate(){
return plate;
}
public void setPlate(String inPlate){
plate = inPlate;
}
}
节点类
public class Node {
Node next;
Car name;
public Node(Node x, Car y){
next = x;
name = y;
}
}
Lstack 类
public class Lstack {
int size;
int numUsed = 0;
Car[] stack;
public Lstack(){
stack = new Car[size];
}
public void push(Car x){
stack[numUsed] = x;
numUsed++;
}
public Car pop(){
Car temp;
numUsed--;
temp = stack[numUsed];
return temp;
}
public boolean isEmpty(){
if(numUsed==0){
return true;
}
else
return false;
}
public int size(){
return numUsed;
}
public void display(){
System.out.println("--------------------------------------------");
System.out.print("TOP | ");
for(int i = 0; i < numUsed; i++){
System.out.print(stack[i].plate +" | ");
}
System.out.println("--------------------------------------------");
}
}
队列类
public class Lqueue {
int size;
int numUsed = 0;
Car[] queue;
public Lqueue(){
queue = new Car[size];
}
public void insert(Car x){
int index = numUsed;
for(int i = numUsed; i >= 0; i--){
queue[index + 1] = queue[index];
index--;
}
queue[0] = x;
}
public Car remove(){
Car temp;
temp = queue[numUsed];
queue[numUsed] = null;
numUsed--;
return temp;
}
public boolean isEmpty(){
if(numUsed==0){
return true;
}
else
return false;
}
public int size(){
return numUsed;
}
public void display(){
System.out.println("--------------------------------------------");
System.out.print("Front | ");
for(int i = numUsed; i >= 0; i--){
System.out.print(queue[i].plate +" | ");
}
System.out.println("--------------------------------------------");
}
}