上一页 1 ··· 24 25 26 27 28 29 30 31 32 ··· 35 下一页
摘要: 1.3.9编写一段程序,从标准输入得到一个缺少左括号的表达式并打印出补全括号之后的中序表达式。例如,给定输入:1+2)*3-4)*5-6)))你的程序应该输出:((1+2)*((3-4)*(5-6)))答:与上一次实现时没有本质区别,都是用两个栈,数据从左到右或是从右到左移动。实现方面略有差别。粗算 阅读全文
posted @ 2018-10-25 13:47 修电脑的龙生 阅读(600) 评论(0) 推荐(0) 编辑
摘要: 1.3.8给定以下输入,给出DoublingStackOfStrings的数组的内容和大小。答:内容:it 大小:2 阅读全文
posted @ 2018-10-25 13:46 修电脑的龙生 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 1.3.6下面这段代码对队列q进行了什么操作?Stack<String> stack=new Stack<String>(); while(!StdIn.isEmpty()) q.enqueue(StdIn.readString()); while(!q.isEmpty()) stack.push( 阅读全文
posted @ 2018-10-25 13:45 修电脑的龙生 阅读(220) 评论(0) 推荐(0) 编辑
摘要: 1.3.7为Stack添加一个方法peek(),返回栈中最近添加的元素(而不弹出它)。答: public Item peek() { Item item=first.item; return item; } 阅读全文
posted @ 2018-10-25 13:45 修电脑的龙生 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 1.3.4编写现代一个Stack的用例Parentheses,从标准输入中读取一个文本流并使用栈判定其中的括号是否配对完整。例如,对于[()]{}{[()()]()}程序应该打印true,对于[(])则打印false。答:上一次发布的code没有考虑栈为空时读入右括号的情形。算法如下:置结果为tru 阅读全文
posted @ 2018-10-25 13:44 修电脑的龙生 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 1.3.5当N为50时下面这段代码会打印什么?从较高的抽象层次描述给定正整数N时这段代码的行为。Stack<Integer> stack =new Stack<Integer>(); while(N>0) { stack.push(N%2); N=N/2; } // for(int d:stack) 阅读全文
posted @ 2018-10-25 13:44 修电脑的龙生 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 1.3.3假设某个用例程序会进行一系列入栈和出栈的混合操作。入栈操作会将整数0到9按顺序压入栈;出栈操作会打印出返回值。下面哪种序列是不可能产生的?a. 4 3 2 1 0 9 8 7 6 5b. 4 6 8 7 5 3 2 9 0 1c. 2 5 6 7 4 8 9 3 1 0d. 4 3 2 1 阅读全文
posted @ 2018-10-25 13:43 修电脑的龙生 阅读(355) 评论(0) 推荐(1) 编辑
摘要: 1.3.1为FixedCapacityStackOfStrings添加一个方法isFull() public boolean isFull() {return N==a.length;}完整Code:public class FixedCapacityStackOfStrings{ private 阅读全文
posted @ 2018-10-25 13:42 修电脑的龙生 阅读(273) 评论(0) 推荐(0) 编辑
摘要: 1.3.2给定以下输入,java Stack的输出是什么?it was - the best -of times - - - it was - the - -答:was bet times of the was the it 阅读全文
posted @ 2018-10-25 13:42 修电脑的龙生 阅读(154) 评论(0) 推荐(0) 编辑
摘要: import java.util.Iterator;public class Queue<Item> implements Iterable<Item>{ private int N; private Node first; private Node last; private class Node 阅读全文
posted @ 2018-10-25 13:41 修电脑的龙生 阅读(100) 评论(0) 推荐(0) 编辑
上一页 1 ··· 24 25 26 27 28 29 30 31 32 ··· 35 下一页