计算机软件技术基础上机编程上机题一:线性表1
建立单向链表;表长任意;2
可交互输出单链表中得内容;3
编写算法计算出自己所建单链表得长度并输出;4
输出自己所建立单链表中得第 K 个结点,并将剩余结点输出;5
将单链表倒排并输出结果#i nclu d e<stdio、h>#includetypede f i n t da t a t ype;typ e de f s t ruc t nod e{ d atatype d a t a; stru c t no d e *nex t;}li n klist; lin k list*C r eatlist() //建立链表// { i nt x; lin k li s t *h, *s; h=N ULL; p r intf("\n p lease in pu t the da te end wit h 0:\n"); p rintf("\n I nput da t a:"); scanf("%d",&x); w hile(x
=0) { s=malloc(sizeof(link l i s t)); s->d a ta=x; s->nex t=h; h=s; printf("\n Inp u t d a ta:"); scanf("%d",&x); } r eturn h; } v oid Putlist(linkl is t *h) //输出单链表中得内容// { link l ist *s; s=h; wh i le(s
=NUL L) { p rint f("%4d",s->da t a); s=s->next; } } i n t L ong(lin kl is t *h) //计算链表得长度// { int i=0; l i nklist *s; s=h; wh ile(s
=N ULL) { i++; s=s->n