import java.util.Stack;

public class StackExample {
    public static void main(String[] args) {
        Stack<Character> stack = new Stack<>();
        stack.push('c');
        stack.push('b');
        stack.push('a');

        while (!stack.isEmpty()) {
            System.out.print(stack.pop() + " ");
        }
    }
}

输出结果为:

a b c 
依次将字母c、b、a放入列表中返回abc 使用java以栈结构实现

原文地址: https://www.cveoy.top/t/topic/bWqP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录