2019-11-03 06:20:17 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "Iterator.h"
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2021-10-28 15:15:51 +00:00
|
|
|
vector<string> channelList = { "新闻频道", "财经频道", "体育频道", "电影频道", "音乐频道", "农业频道", "四川卫视", "成都卫视" };
|
|
|
|
// 创建电视
|
2019-11-03 06:20:17 +00:00
|
|
|
Television *tv = new Television(channelList);
|
2021-10-28 15:15:51 +00:00
|
|
|
// 创建遥控器
|
2019-11-03 06:20:17 +00:00
|
|
|
Iterator *remoteControl = tv->createIterator();
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
// 顺序遍历
|
|
|
|
printf("顺序遍历:\n");
|
2019-11-03 06:20:17 +00:00
|
|
|
remoteControl->first();
|
2021-10-28 15:15:51 +00:00
|
|
|
// 遍历电视所有频道
|
2019-11-03 06:20:17 +00:00
|
|
|
while (remoteControl->hasNext()){
|
|
|
|
remoteControl->currentChannel();
|
|
|
|
remoteControl->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
|
2021-10-28 15:15:51 +00:00
|
|
|
// 逆序遍历
|
2021-10-29 13:33:26 +00:00
|
|
|
printf("逆序遍历:\n");
|
2019-11-03 06:20:17 +00:00
|
|
|
remoteControl->last();
|
2021-10-28 15:15:51 +00:00
|
|
|
// 遍历电视所有频道
|
2019-11-03 06:20:17 +00:00
|
|
|
while (remoteControl->hasPrevious()){
|
|
|
|
remoteControl->currentChannel();
|
|
|
|
remoteControl->previous();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n\n");
|
|
|
|
system("pause");
|
2020-11-29 03:17:40 +00:00
|
|
|
|
|
|
|
delete tv;
|
2021-10-13 15:10:44 +00:00
|
|
|
delete remoteControl;
|
2020-11-29 03:17:40 +00:00
|
|
|
|
2019-11-03 06:20:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|