大数据结构六个主要算法程序(c版).doc

大数据结构六个主要算法程序(c版).doc

ID:56523695

大小:82.04 KB

页数:13页

时间:2020-06-27

大数据结构六个主要算法程序(c版).doc_第1页
大数据结构六个主要算法程序(c版).doc_第2页
大数据结构六个主要算法程序(c版).doc_第3页
大数据结构六个主要算法程序(c版).doc_第4页
大数据结构六个主要算法程序(c版).doc_第5页
资源描述:

《大数据结构六个主要算法程序(c版).doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、1.顺序表#include#includetypedefstruct{intnum;charname[20];}Sqstu;Sqstustu[4];Sqstustud;voidcreat();voidinsert();voiddel();voidmain(){creat();printf("请输入要插入学生的信息:");insert();printf("请输入要删除学生的学号:");del();}voidcreat(){inti;for(i=0;i<3;i++)scanf("

2、%d%s",&stu[i].num,stu[i].name);printf("学生的信息为:");for(i=0;i<3;i++)printf("%-10d%s",stu[i].num,stu[i].name);}voidinsert(){inti,j;scanf("%d%s",&stud.num,stud.name);for(i=0;stud.num>stu[i].num;i++)j=i;for(i=3;i>j;i--){stu[i].num=stu[i-1].num;strcpy(stu[i].name,st

3、u[i-1].name);}stu[j+1].num=stud.num;strcpy(stu[j+1].name,stud.name);printf("现在,学生的信息为:");for(i=0;i<4;i++)printf("%-10d%s",stu[i].num,stu[i].name);}voiddel(){inti;scanf("%d",&stud.num);for(i=0;stud.num!=stu[i].num;i++)i=i;for(i;i<4;i++){stu[i]=stu[i+1];}printf

4、("现在,学生的信息为:");for(i=0;i<3;i++)printf("%-10d%s",stu[i].num,stu[i].name);}2.链表#include#include#defineNULL0#defineLENsizeof(structstudent)structstudent{intnum;charname[20];structstudent*next;};intn;structstudent*creat(){structstudent*head;str

5、uctstudent*p1,*p2;n=0;p1=p2=(structstudent*)malloc(LEN);scanf("%d%s",&p1->num,p1->name);head=NULL;while(p1->num!=0){n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(structstudent*)malloc(LEN);scanf("%d%s",&p1->num,p1->name);}p2->next=NULL;returnhead;}voidprint(str

6、uctstudent*head){structstudent*p;printf("Now,These%drecordsare:",n);p=head;if(head!=NULL)do{printf("%d,%s",p->num,p->name);p=p->next;}while(p!=NULL);}structstudent*insert(structstudent*head,structstudent*stud){structstudent*p0,*p1,*p2;p1=head;p0=stud;if(hea

7、d==NULL){head=p0;p0->next=NULL;}else{while((p0->num>p1->num)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(p0->num<=p1->num){if(head==p1)head=p0;elsep2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;}}n=n+1;returnhead;}structstudent*del(structstudent*head,intnum

8、){structstudent*p1,*p2;p1=head;if(head==NULL){printf("listnull!");returnhead;}while((num!=p1->num)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(num==p1->num){i

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。