首页 > 代码库 > LinkList
LinkList
#define LOCAL#include<cstdio>#include<cstdlib>#include<iostream>using namespace std;typedef int ElemType;typedef struct Node{ ElemType data; struct Node *next;}Node,*LinkList;void DisplayList(LinkList L){ Node *p=L->next; cout<<"display:"<<L->data<<endl; while(p!=NULL) { cout<<p->data<<","; p=p->next; }}void InitList(LinkList *L){ (*L)=(LinkList)malloc(sizeof(Node)); (*L)->next=NULL;}void CreateHeadList(LinkList L){ Node *p; ElemType a; L->data=http://www.mamicode.com/0; while(cin>>a) { p=(Node *)malloc(sizeof(Node)); p->data=http://www.mamicode.com/a; p->next=L->next; L->next=p; }}void CreateHeadList1(LinkList L){ Node *p,*h; h=L->next; ElemType a; L->data=http://www.mamicode.com/0; while(cin>>a) { p=(Node *)malloc(sizeof(Node)); p->data=http://www.mamicode.com/a; L->data++; p->next=h; h=p; } L->next=h;//注意此处一定要有,就是把h连接到L->next后 }void CreateTailList(LinkList L){ Node *p,*r; ElemType a; r=L; L->data=http://www.mamicode.com/0; while(cin>>a) { p=(Node *)malloc(sizeof(Node)); p->data=http://www.mamicode.com/a; p->next=NULL; L->data++; r->next=p; r=p; } r->next=NULL; }void UseT(LinkList &L){ //Node *p=(*L).next; Node *p=L->next; cout<<endl<<"&L:"<<endl; while(p!=NULL) { cout<<p->data<<","; p=p->next; } cout<<endl;}int main(){#ifdef LOCAL freopen("2.in","r",stdin); freopen("2.out","w",stdout);#endif LinkList Head; InitList(&Head); //CreateHeadList1(Head); CreateTailList(Head); DisplayList(Head); UseT(Head);//放进去Head 然后&把Head打包 return 0;}
display:101,2,3,4,5,6,7,8,9,10,&L:1,2,3,4,5,6,7,8,9,10,
LinkList
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。