线性表的应用—单链表操作.docVIP

  • 2
  • 0
  • 约2.41千字
  • 约 3页
  • 2018-06-27 发布于河南
  • 举报
线性表的应用—单链表操作

#include stdio.h #includestdlib.h typedef struct node { int data; struct node *next; }LNode,*Linklist; Linklist Creat1()//尾插法建立不带头结点的单链表 { Linklist L=NULL; LNode *s,*t=NULL; int x; printf(请输入表中数据,以0结束(不带头结点):\n); scanf(%d,x); while(x!=0) { s=(LNode*)malloc(sizeof(LNode)); s-data=x; if(L==NULL) L=s; else t-next=s; t=s; scanf(%d,x); } if(t!=NULL) t-next=NULL; return(L); } Linklist Creat2()//尾插法建立带头结点的单链表 { Linklist head=(Linklist)malloc(sizeof(LNode)); LNode *p,*r; int x; r=head; printf(请输入表中数据,以0结束(带头结点):\n); scanf(%d,x); while(x!=0) { p=(LNode*)malloc(sizeof(LNode));

文档评论(0)

1亿VIP精品文档

相关文档