Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 节点链表堆栈_Java_Stack - Fatal编程技术网

Java 节点链表堆栈

Java 节点链表堆栈,java,stack,Java,Stack,刚刚结束春假,很难记住这些东西 现在我正在尝试创建一个Lstack类,该类将创建一个堆栈ADT,该堆栈ADT实现为节点的链接列表 这是Lstack类 public class Lstack { int numUsed = 0; Lstack list = new Lstack(); public Lstack(){ } public void push(Car x){ } } 如何将Car x(对象)推入堆栈?堆栈是一种后进先出结构。 因此,如

刚刚结束春假,很难记住这些东西

现在我正在尝试创建一个Lstack类,该类将创建一个堆栈ADT,该堆栈ADT实现为节点的链接列表

这是Lstack类

public class Lstack {
    int numUsed = 0;
    Lstack list = new Lstack();
    public Lstack(){
    }
    public void push(Car x){

    }
}

如何将Car x(对象)推入堆栈?

堆栈是一种后进先出结构。
因此,如果您在
链表
的支持下实现它,那么您应该确保
推到
链表
同一侧
由于这是一个家庭作业,我不会提供更多的信息。这应该足够了

堆栈是一种后进先出结构。
因此,如果您在
链表
的支持下实现它,那么您应该确保
推到
链表
同一侧
由于这是一个家庭作业,我不会提供更多的信息。这应该足够了

堆栈是后进先出(LIFO)结构。所以我会这样说:

Car
类必须具有同一类的
next
成员:

class Car {
    String brand;
    Car next;
    public Car(String brand, Car car) {
        this.brand = brand;
        next = car;
    }
    // And the class code goes on
}
至于链表:

 class Llist {
     Car top;
     public Llist() {
         top = null;
     }
     public void push(String carBrand) {
         top = new Car(carBrand, top);
     }
 }

举个例子。

堆栈是后进先出(LIFO)结构。所以我会这样说:

Car
类必须具有同一类的
next
成员:

class Car {
    String brand;
    Car next;
    public Car(String brand, Car car) {
        this.brand = brand;
        next = car;
    }
    // And the class code goes on
}
至于链表:

 class Llist {
     Car top;
     public Llist() {
         top = null;
     }
     public void push(String carBrand) {
         top = new Car(carBrand, top);
     }
 }
举个例子。

我做得对吗

public class Lstack {
    int size;
    int numUsed = 0;
    Car[] list;
    public Lstack(){
        list = new Car[size];
    }
    public void push(Car x){
        list[numUsed] = x;
        numUsed++;
    }
    public Car pop(){
        Car temp;
        numUsed--;
        temp = list[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(list[i].plate +" | ");
        }
    }

}
公共类Lstack{
整数大小;
int numUsed=0;
车辆[]清单;
公共Lstack(){
列表=新车[尺寸];
}
公共空间推送(x车){
列表[numUsed]=x;
numUsed++;
}
公共汽车{
汽车温度;
傻傻的--;
temp=列表[numUsed];
返回温度;
}
公共布尔值为空(){
如果(numUsed==0){
返回true;
}
其他的
返回false;
}
公共整数大小(){
回眸;
}
公共空间显示(){
System.out.println(“--------------------------------------------------”);
系统输出打印(“顶部|”);
for(int i=0;i
我做对了吗

public class Lstack {
    int size;
    int numUsed = 0;
    Car[] list;
    public Lstack(){
        list = new Car[size];
    }
    public void push(Car x){
        list[numUsed] = x;
        numUsed++;
    }
    public Car pop(){
        Car temp;
        numUsed--;
        temp = list[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(list[i].plate +" | ");
        }
    }

}
公共类Lstack{
整数大小;
int numUsed=0;
车辆[]清单;
公共Lstack(){
列表=新车[尺寸];
}
公共空间推送(x车){
列表[numUsed]=x;
numUsed++;
}
公共汽车{
汽车温度;
傻傻的--;
temp=列表[numUsed];
返回温度;
}
公共布尔值为空(){
如果(numUsed==0){
返回true;
}
其他的
返回false;
}
公共整数大小(){
回眸;
}
公共空间显示(){
System.out.println(“--------------------------------------------------”);
系统输出打印(“顶部|”);
for(int i=0;i
我知道,我的问题是如何使用对象实现这一点。如果我只是输入字符串或int,我就会知道如何做。
Lstack
我想这是列表的自定义实现吗?这将存储对
汽车
列表下一个节点的引用
我知道,我的问题是如何使用对象来实现这一点。如果我只是输入字符串或int,我就会知道如何做。
Lstack
我想这是列表的自定义实现吗?这将存储对
汽车
列表下一个节点的引用