定义 迭代器模式(Iterator
Pattern)提供一种方法访问一个容器对象中各个元素,而又不需暴露该对象内部细节。 迭代器模式通用类图 Iterator抽象迭代器
抽象迭代器负责定义访问和遍历元素的接口,而且基本上是有固定的3个方法:First()获取第一个元素,Next()访问下一个元素,I...
分类:
其他好文 时间:
2014-06-09 20:55:24
阅读次数:
316
#include using namespace std;struct Node{ Node
*next; int elem;};void creatList(Node* &head){ head = new Node; int elem;
cin>>elem; ...
分类:
其他好文 时间:
2014-06-09 16:07:55
阅读次数:
229
都表示承诺保证的含义。1. pledge 用法更为正式,用于郑重场合 The French
president is pledging $150 million in French aid next year. The president
pledged himself to increase .....
分类:
其他好文 时间:
2014-06-09 00:20:41
阅读次数:
236
在面试,笔试的过程中经常会遇到面试官问这种问题,实现单链表的倒置方法。现在对单链表的倒置犯法做个记录,方便自己以后查看。单链表的定义: 1 public
class Node { 2 3 int v; 4 Node next; 5 public Node(){ ...
分类:
编程语言 时间:
2014-06-08 22:22:59
阅读次数:
352
题目
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).
For example:
G...
分类:
其他好文 时间:
2014-06-08 17:29:07
阅读次数:
315
Java中Iterator的用法
迭代器(Iterator):提供一个方法访问一个容器(container)对象中各个元素,而又不需暴露该对象的内部细节!
Iterator内有三种方法:
1、Boolean hasNext(); 如果仍有元素可以迭代,则返回true
2、Object next(); 返回迭代的下一个元素
3、void remo...
分类:
其他好文 时间:
2014-06-08 17:18:39
阅读次数:
147
【题目】
Follow up for problem "Populating Next Right Pointers in Each Node".
What if the given tree could be any binary tree? Would your previous solution still work?
Note:
You may only use constant extra space.
For example,
Given the following binary tre...
分类:
其他好文 时间:
2014-06-08 15:46:22
阅读次数:
303
遍历List集合中的元素的方法有两种:
第一种:利用迭代器遍历
代码1:
// 迭代器
Iterator it=list.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}或者代码2:
for(Iterator it=list.iterator();it.hasNext();)
{
System.o...
分类:
其他好文 时间:
2014-06-08 15:22:50
阅读次数:
189
Description
A robot has been programmed to follow the instructions in its path. Instructions for the next direction the robot is to move are laid down in a grid. The possible instructions are
...
分类:
其他好文 时间:
2014-06-08 04:38:32
阅读次数:
386
ListIterator的父接口是Iterator,是List接口中特有的迭代器。
ListIterator在Iterator的基础上,又新添了很多方法:
Iterator中的方法:
1、判断是否有下一个元素:hasNext();
2、获取下一个元素: next();
3、删除迭代器指向的元素:remove();
ListIterator新添的方法:
4、判断...
分类:
其他好文 时间:
2014-06-08 03:15:53
阅读次数:
246