正在加载图片...
struct student *createlist( void) struct student whead=NLL,ˉpr,p:;腆开始时是空链表 t count=0: char c: printf(“开始建立链表,请根据提示输入数据:”) 创建链表 do/*循环实现建立链表* printf \nPlease press yto insert one new node, press 'nto finish: ) c= getchar: if ((cl='y'llcl='y)&&(cl='n'llcl='ND) 如果键入既不是'y',又不是"n'则循环继续进行* puts( you must input yor n): continue if〔(c=='n'|c='N")∧如果键入的是n'循环退出* break CreateNodeo if〔 count=0)如果是第一个节点将新节点链至头节点后*/ head=p: pr=head://使用p跟踪当前节点的前一个节点 else/不是第一个节点,将新建节点接到链表的结尾p处* pr->next P: pr=p->next:/使用pr跟踪当前节点的前一个节点 count++ 3 while(1) return(head):返回链表的头结点*11 struct student *createList( void ) { struct student *head=NULL, *pr,p; /*开始时是空链表*/ int count=0; char c; printf(“开始建立链表,请根据提示输入数据:”); do/*循环实现建立链表*/ { printf("\nPlease press 'y' to insert one new node,press 'n' to finish:"); c = getchar(); if ((c!='y'||c!='Y')&&(c!='n'||c!='N')) {/* 如果键入既不是' y ' ,又不是'n'则循环继续进行 */ puts("you must input 'y' or 'n'"); continue; } if ((c=='n'||c=='N')) /* 如果键入的是'n'循环退出 */ break; p= CreateNode(); if (count==0)/* 如果是第一个节点,将新节点链至头节点后*/ { head=p; pr = head;//使用pr跟踪当前节点的前一个节点 } else/* 不是第一个节点,将新建节点接到链表的结尾pr处 */ { pr->next = p; pr = pr->next;//使用pr跟踪当前节点的前一个节点 } count++; } while(1); return(head); /*返回链表的头结点*/ } 创建链表
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有