说明:本文件为博客所有指针系列代码共用头文件
命名:linklist.h
代码:
#ifndef linklist_h_ #define linklist_h_ #include<iostream> typedef struct lnode { int value; lnode* next; } node,*pnode; pnode head; void crtlist() { int i; head=new node; head->value=0; head->next=NULL; pnode p,q; q=head; for(i=1;i<5;i++) { p=new node; p->value=i; p->next=NULL; q->next=p; q=p; } } pnode getlist() { int i; pnode phead=new node; phead->value=0; phead->next=NULL; pnode p,q; q=phead; for(i=1;i<5;i++) { p=new node; p->value=i; p->next=NULL; q->next=p; q=p; } return phead; } void prtlist() { using namespace std; pnode p=head; while(p!=NULL) { cout<<p->value<<" "; p=p->next; } cout<<endl; } void prtlist(pnode head) { using namespace std; pnode p=head; while(p!=NULL) { cout<<p->value<<" "; p=p->next; } cout<<endl; } void prtnode(pnode p) { using namespace std; cout<<"print node‘s value:"<<p->value<<endl; } #endif
crtlist:创建链表
prtlist输出链表
prtnode 打印节点
原文:http://blog.csdn.net/pyz_tech/article/details/23692867