高级农民
- 积分
- 1752
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2015-3-18
- 最后登录
- 1970-1-1
|
2 Squaring a List
- public static IntList SquareDestructive(IntList L) {
- IntList p = L;
- while (p != null) {
- p.head = p.head * p.head;
- p = p.tail;
- }
- return p;
- }
- public static IntList SquareNonDestructive(IntList L) {
- if (L == null) {
- return null;
- } else {
- IntList tail = SquareNonDestructive(L.tail);
- IntList p = new IntList(L.head * L.head, tail);
- }
- return p;
- }
复制代码
3 Reversing Linked Lists
- public static IntList reverseNonDestructive(IntList lst) {
- IntList p = null;
- if (lst == null) {
- return null;
- }
- while (lst != null) {
- IntList p = new IntList(lst.head, p);
- lst = lst.tail;
- }
- return p;
- }
复制代码 |
|