forked from FengJungle/DesignPattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (32 loc) · 858 Bytes
/
main.cpp
File metadata and controls
39 lines (32 loc) · 858 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include "Iterator.h"
int main()
{
vector<string> channelList = { "新闻频道", "财经频道", "体育频道", "电影频道", "音乐频道", "农业频道", "四川卫视", "成都卫视" };
// 创建电视
Television *tv = new Television(channelList);
// 创建遥控器
Iterator *remoteControl = tv->createIterator();
// 顺序遍历
printf("顺序遍历:\n");
remoteControl->first();
// 遍历电视所有频道
while (remoteControl->hasNext()){
remoteControl->currentChannel();
remoteControl->next();
}
printf("\n\n");
// 逆序遍历
printf("逆序遍历:\n");
remoteControl->last();
// 遍历电视所有频道
while (remoteControl->hasPrevious()){
remoteControl->currentChannel();
remoteControl->previous();
}
printf("\n\n");
system("pause");
delete tv;
delete remoteControl;
return 0;
}