使用STL之list实现链表逆置
来源:互联网 发布:野外直播用什么网络 编辑:程序博客网 时间:2024/06/11 19:35
//STL之链表,比自己做链表要简单多了,其他函数可以自己看看,比如插入、删除、查找、排序等
#include <iostream>
#include <string>
#include <list>
using namespace std;
struct Node
...{
string name;
int age;
};
list<Node> createListQueue(int n)//建立队列链表
...{
list<Node> myList;
Node t;
for(int i=0;i<n;i++)
...{
cin >> t.name >> t.age;
myList.push_back(t);
}
return myList;
}
void prtList(list<Node> myList)//输出链表
...{
list<Node>::iterator it;
for(it=myList.begin(); it!=myList.end(); it++)
...{
cout << it->name << " " << it->age << endl;
}
}
list<Node> createListStack(int n)//建立栈链表
...{
list<Node> myList;
Node t;
for(int i=0;i<n;i++)
...{
cin >> t.name >> t.age;
myList.push_front(t);
}
return myList;
}
void run()
...{
int n;
cin>>n;
//假的链表逆置
/**//*list<Node> myList=createListStack(n);
prtList(myList);*/
//真的链表逆置
list<Node> myList=createListQueue(n);
myList.reverse();//直接使用reverse函数
prtList(myList);
}
int main()
...{
int total;
cin>>total;
for(int now=1; now<=total; now++) run();
return 0;
}
#include <iostream>
#include <string>
#include <list>
using namespace std;
struct Node
...{
string name;
int age;
};
list<Node> createListQueue(int n)//建立队列链表
...{
list<Node> myList;
Node t;
for(int i=0;i<n;i++)
...{
cin >> t.name >> t.age;
myList.push_back(t);
}
return myList;
}
void prtList(list<Node> myList)//输出链表
...{
list<Node>::iterator it;
for(it=myList.begin(); it!=myList.end(); it++)
...{
cout << it->name << " " << it->age << endl;
}
}
list<Node> createListStack(int n)//建立栈链表
...{
list<Node> myList;
Node t;
for(int i=0;i<n;i++)
...{
cin >> t.name >> t.age;
myList.push_front(t);
}
return myList;
}
void run()
...{
int n;
cin>>n;
//假的链表逆置
/**//*list<Node> myList=createListStack(n);
prtList(myList);*/
//真的链表逆置
list<Node> myList=createListQueue(n);
myList.reverse();//直接使用reverse函数
prtList(myList);
}
int main()
...{
int total;
cin>>total;
for(int now=1; now<=total; now++) run();
return 0;
}
- 使用STL之list实现链表逆置
- STL之list实现
- stl之list使用
- STL之LIST使用
- STL之LIST使用
- STL之list容器的实现框架
- 使用List模拟实现STL中的Queue
- stl之二: list使用总结【转】
- STL之list基本使用实例
- STL LIST实现
- STL LIST实现 - 2
- STL List 实现(1)
- STL list实现(二)
- STL-list实现
- STL-List实现
- [STL]List的实现
- <STL>模拟实现List
- STL List 的实现
- 一个时钟程序(c语言)
- Vb6.0、2003 和Vb2005有和不同?
- 君臣对话
- 简单的calendar
- 劝学
- 使用STL之list实现链表逆置
- 转发:::一个简单的写excel文件的类
- Ubuntu Linux系统中使用命令行修改时区
- 设计人生
- 相约路口,携手前行... ...
- 网关
- 华山之险、人生之路------2007年8月18日
- 一些常用的正则表达式
- 一个坚定地向目标迈进的人,整个世界都会为他让路.