经典算法——箱子排序
来源:互联网 发布:大连 大数据 招聘 编辑:程序博客网 时间:2024/05/17 20:22
#include<stdio.h>
#include<alloc.h>
#include<string.h>
typedef struct _student{
char name[20];
int number;
struct _student *next;
}stu;
stu student[40];
int main()
{
int n,i,j=0,c;
stu *head,*tmp,*p,*bottom;
printf("pleade input the number of student:");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("please input %2d ge student:",(i+1));
scanf("%s %d",&student[i].name,&student[i].number);
}
p=(stu *)malloc(sizeof(stu));
p->number=student[j].number;
strcpy(p->name,student[j].name);
head=p;
bottom=p;
for(j=1;j<n;j++){
if(student[j].number<head->number){
tmp=(stu *)malloc(sizeof(stu));
tmp->number=student[j].number;
strcpy(tmp->name,student[j].name);
tmp->next=head;
p=tmp;
head=tmp;
}
else if(student[j].number>bottom->number){
tmp=(stu *)malloc(sizeof(stu));
tmp->number=student[j].number;
strcpy(tmp->name,student[j].name);
bottom->next=tmp;
bottom=tmp;
}
else {
for(head=p;head->next->number!=bottom->number;head=head->next){
if((student[j].number<head->next->number)&&(student[j].number>head->number)){
tmp=(stu *)malloc(sizeof(stu));
tmp->number=student[j].number;
strcpy(tmp->name,student[j].name);
tmp->next=head->next;
head->next=tmp;
break;
}
}
}
}
head=p;
for(c=0;c<n;c++){
printf("%d: %s/t %d/n",c+1,head->name,head->number);
head=head->next;
}
return 0;
}
输入的数据:
pleade input the number of student: 7
please input 1 ge student:wo 65
please input 2 ge student:ta 44
please input 3 ge student:ni 3
please input 4 ge student:sa 66
please input 5 ge student:bu 24
please input 6 ge student:ti 35
please input 7 ge student:qi 53
输出的结果:
1: ni 3
2: bu 24
3: ti 35
4: ta 44
5: qi 53
6: wo 65
7: sa 66
- 经典算法——箱子排序
- 箱子排序算法
- 算法复习--------------箱子排序
- 常见排序算法——桶排序(箱子排序)bucket Sort
- 经典排序算法——快速排序
- 经典排序算法——快速排序
- 经典算法排序——插入排序
- 经典算法排序——希尔排序
- 经典排序算法——冒泡排序
- 经典排序算法——快速排序
- 经典排序算法——归并排序
- 经典排序算法——桶排序
- 经典排序算法——冒泡排序
- 经典排序算法——冒泡排序
- 经典排序算法——插入排序
- 经典排序算法——选择排序
- 经典排序算法——快速排序
- 经典排序算法——归并排序
- ASP.NET中IP地址,当前用户的方法属性大整合
- [GCC] 4.1.1 is different
- ASP.NET中使用脚本代码保护功能
- 用VS2005开发ASP.NET 2.0数据库程序
- 中科院、复旦、上交、北大等历年考博英语试题真题(2000-2006)!
- 经典算法——箱子排序
- Asp, Asp.Net 无组件上传, 进度条, 断点续传
- Programming Methodology?
- 在eclipse中调试turbine代码
- Django的Ajax开发,Dojo + SAjax
- 再战SVOHOST.exe、sxs.exe和command.com
- 北京的春天
- 数学之美--防伪系统(1)
- Google Maps API 2 中文文档