#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);
}
【c++程序】链表
最新推荐文章于 2024-08-19 23:23:47 发布