为了帮助你实现一个Java堆栈类,该类能够存储字符串元素,并提供push、pop、peek、empty和getsize函数,我将按照你的要求分点给出详细的解答,并提供相应的代码片段。 1. 创建一个Java类来表示堆栈,并声明一个私有变量来存储字符串元素 首先,我们需要创建一个名为StringStack的类,并使用一个私有变量(例如ArrayList<...
用栈实现队列:使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部。 pop() -- 从队列首部移除元素。 peek() -- 返回队列首部的元素。 empty() -- 返回队列是否为空。 思路:使用辅助栈。程序:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
push(e);push(f);push(g);push(h);push(i);push(k);} } class StackApp { public static void main(String[] args){ StackX stackX=new StackX(10);stackX.tofun(1,2,3,4,5,6,7,8,9,10);while( !stackX.isEmpty() ) // until it's empty,{ // delete item fro...