C++ 模板类链表迭代器与<list.h>迭代器基本介绍
本程序基于本博客C++模板类链表基础上实现
主程序 main.cpp
//Written by Xuebi
//本程序使用模板类创建链表,并实现添加数据,删除数据,反转链表,连接链表功能
//本程序在实现以上功能的前提下,一方面介绍了系统自带的list类,并演示了基本操作,另一方面,在上篇博客的基础上增加了自己设计的迭代器。
//系统的迭代器和额外编写的迭代器使得能对连边里面的数据进行具体的操作,值得注意的是,系统自带的list类功能当然更加完善
#include <iostream>
#include "List.h"
#include <list>
using namespace std;
int main()
{
cout<<"The first part is the List class saved in the system: ";
std:list<int> ListSystem;
ListSystem.push_front(10);//往链头输入数据interger 10
ListSystem.push_front(20);//往链头输入数据interger 20
ListSystem.push_front(30);//往链头输入数据interger 30
ListSystem.push_front(40);//往链头输入数据interger 40
ListSystem.push_back(0);//往链尾输入数据interger 0
std::list<int>::iterator i=ListSystem.begin();//讲链表开头的地址赋值与迭代器 i
cout<<*i;
i++;
while(i!=(ListSystem.end()))
{
cout<<"->";
cout<<*i;
++i;
}
cout<<endl;
cout<<"The following is written by myself:"<<endl;
List<int> st;
st.Insert(10);
st.Insert(20);
st.Insert(30);
st.Insert(40);