相关疑难解决方法(0)

java.util.Stack的Iterator中是否有错误?

今天我试图在java.util.Stack课堂上推进,然后Iterator通过项目使用迭代(不使用pop).我期待着LIFO的财产但却感到惊讶.

这是我正在尝试的代码.

import java.util.*;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        RobStack<Integer> rstack = new RobStack<Integer>(); // Correct Implementation
        Stack<Integer> jstack = new Stack<Integer>(); // Default Java Implementation
        rstack.push(0); jstack.push(0);
        rstack.push(1); jstack.push(1);
        rstack.push(2); jstack.push(2);
        rstack.push(3); jstack.push(3);

        System.out.print("Algo Stack: ");
        for (int i : rstack)
            System.out.print(i + " ");
        System.out.print("\nJava Stack: ");
        for (int i : jstack)
            System.out.print(i + " ");
    }

}
Run Code Online (Sandbox Code Playgroud)

以上程序的输出如下:

Algo Stack: 3 2 1 0 
Java Stack: …
Run Code Online (Sandbox Code Playgroud)

java algorithm stack data-structures

32
推荐指数
2
解决办法
8933
查看次数

我怎样才能在Kotlin中使用堆栈?

如何在Kotlin中使用Stack(来自java)?

或者还有其他选择吗?

  • 我正在尝试将列表转换为堆栈

谢谢

kotlin

9
推荐指数
7
解决办法
1万
查看次数

标签 统计

algorithm ×1

data-structures ×1

java ×1

kotlin ×1

stack ×1