车友信息管理系统程序设计内容摘要:

(\n)。 count++。 } p=pnext。 } if(count==0) printf(it is not in the list!\n)。 return 0。 } struct node *InsertAfter(struct node *head,Type data) //尾部插入 { struct node *p,*p1。 p=(struct node*)malloc(size)。 //利用指针 p 申请动态空间 pdata=data。 //数据域赋值 pnext=NULL。 //指针域直接赋值为空,因为它是新链最后的结点 if(head==NULL) //如果链表原来为空 { head=p。 //修改头指针 return head。 //返回头指针 } p1=head。 //链表原来非空,则指针 p1 从头指针开始 while(p1next) //如果指针还没有指向链表的最后一个结点处 { p1=p1next。 //p1 顺着链向后移动 } //循环停止时, p1 指向了链表的最后一个结点处 p1next=p。 //将新结点连在 p1 之后 return head。 //返回头指针 } struct node *InsertOrder(struct node *head,Type data,int condition) //有序插入法 { struct node *p,*p1,*p2。 p2=head。 p=(struct node*)malloc(size)。 //利用指针 p 申请动态空间 pdata=data。 //数据域赋值 pnext=NULL。 //指针域直接赋值为空,以后根据插入位置再修改 if(head==NULL) //原链表为空时的插入 { head=p。 //新插入结点成为头结点 return head。 } //原链表不为空时的插入, larger 是一个通用函数 while(p2amp。 amp。 larger(pdata ,p2data,condition)) //第一参数大于第二参 数,返回真 { p1=p2。 //p1 是 p2 的前趋结点,二者同时后移 p2=p2next。 } if(head==p2) //如果要在最前面插入,则要修改 head 指针 head=p。 else //否则 p 插在 p1 的后面 p1next=p。 pnext=p2。 //p2 作为 p 的后继结点,即 p 插在 p1 和 p2 之间 return head。 //返回头指针 } struct node *CreateInsert() //按序插入法新建链表 { struct node *head。 Type data。 head=NULL。 printf(Input data end with 0:\n)。 readNode(amp。 data)。 //调用 readNode 输入一个结点的数据域的值 while(!endWith(data)) //endWith(data)函数值为真时结束链表结点的生成 { head=InsertOrder(head,data,1)。 //直接 InserOrder 函数插入新结点 readNode(amp。 data)。 //继续读入下一个结点的数据域的值 } return head。 //返回头指针 } struct node *Delete(struct node *head,Type data) //删除结点 { struct node *p=head,*q=NULL。 if(head==NULL) //如果原来链表为空,则给出提示信息并返回 { printf(\nNo Records\n)。 return head。 } while(pamp。 amp。 !equal(pdata,data,1)) //如果链表非空,则从第 1 个结点开始比较 { q=p。 //如果没有找到要删除的结点,则 p 和 q同时向后移 p=pnext。 //动一个结点位置, q 始终是 p 的前趋 } if(p) //如果找到需要删除的结点 { if(q) //如果删除的不是第一个结点 qnext=pnext。 //修改的域,使 p 的后继成为 q 的后继 else //如果删除的是第一个结点( q 保持初值 NULL) head=headnext。 //修改 head 指针 free(p)。 //释放指针 p 所指向的结点空间 } else //如果没有待删除的点 printf(it is not in the list.\n)。 //则输出提示信息 return head。 //返回头指针 } struct node *Recerse(struct node *head) //单链表的逆置 { struct node *p=head,*q。 //p 是当前要处理的结点指针,从原 head 开始 head=NULL。 //head 置为空值 while(p) //用遍历思想 { q=pnext。 //q 记下 p 的后继结点,便于下次继续处理 pnext=head。 //修改 p 的 next 域,前趋变后趋 head=p。 //head 指向已逆置完成的新的第一个结点处 p=q。 //p 移向原链表的下一个结点处,再进行处理 } return head。 //返回头指针 } struct Carfriend { long VIPnum。 char name[10]。 char sex[7]。 char job[10]。 int age[2]。 char brand[10]。 char type[7]。 char colour[8]。 }。 typedef struct Carfriend Type。 const int sizeCfr=sizeof(Type)。 //车友信息所需要的内存空间大小 struct node { Type data。 struct node *next。 }。 const int size=sizeof(struct node)。 //结点所需要的内存空间的大小 include include void printHead() //打印表头函数 { printf(%8s%9s%9s%9s%7s%7s%13s%7s%7s\n,会员名 ,昵称 ,性别 ,职业 ,驾龄 ,年龄,车辆品牌 ,车款 ,颜色 )。 } void printNode(Type data) //输出结点所有数据域的值 { int i。 printf(%8ld,)。 printf(%9s,)。 printf(%9s,)。 printf(%9s,)。 for(i=0。 i2。 i++) printf(%7d,[i])。 printf(%13s,)。 printf(%7s,)。 printf(%7s,)。 } void readNode(Type *pdata) //根据提示读入结点的相关数据域的值 { int i。 printf(Input one carfriend\39。 s information\n)。 printf(VIPnum: )。 scanf(%ld,amp。 pdataVIPnum)。 printf(name: )。 scanf(%s,amp。 pdataname)。 printf(sex: )。 scanf(%s,amp。 pdatasex)。 printf(job: )。 scanf(%s,amp。 pdatajob)。 printf(Input the driving years and the age of the carfriend\n)。 for(i=0。 i2。 i++) { scanf(%d,amp。 pdataage[i])。 } printf(brand of the car: )。 scanf(%s,amp。 pdatabrand)。 printf(type: )。 scanf(%s,amp。 pdatatype)。 printf(colour of the car: )。 scanf(%s,amp。 pdatacolour)。 } int endWith(Type data) //输入结点数据时会员名域为 0 作为结束条件 { return ==0。 } int equal(Type data1,Type data2,int condition) { if(condition==1) if(strcmp(,)==0) return 0。 else return 1。 else if(condition==2) if(strcmp(,)==0) return 0。 else r。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。