您的位置:首页 > 编程语言 > C语言/C++

【c++程序】链表

2016-05-25 22:12 344 查看
#include<iostream>
using namespace std;

typedef int T;

struct Node
{
T data;
Node* next;
Node(const T& d):data(d),next(NULL){}
operator T(){return data;}
};

void showlist(Node* head)
{
Node* p=head;
while(p!=NULL)
{
cout<<*p<<' ';
p=p->next;//(*p).next
}
}

int main()
{
Node a(10),b(20),c(30),d(40),e(50),f(60);
cout<<"a="<<a<<",b="<<b<<endl;
cout<<"***********************************"<<endl;
a.next=&b;
b.next=&c;
c.next=&d;
showlist(&a);
cout<<endl;
cout<<"***********************************"<<endl;
Node *p=&a;
while(p!=NULL)
{
cout<<*p<<' ';
p=(*p).next;
}
cout<<endl;
e.next=b.next;//&c;
b.next=&e;
showlist(&a);
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: