c语言简短的泡沫排序法编程,冒泡排序--简单(c语言)
//
//? main.cpp
//? bubble
//
//? Created by duanqibo on 2019/7/17.
//? Copyright ? 2019年 duanqibo. All rights reserved.
//? 冒泡排序 c語言
#include
#include
#include
#include
#define N 4
typedef struct student
{
int num;
char name[20];
char sex[2];
int age;
}stu[N];
//按姓名冒泡排序
void bubble_sort(struct student stud[],int n)
{
int i,j;
struct student temp;
printf("\n\t按學生姓名排序,采用冒泡排序\n\n");
for(i=0;i
{
for(j=0;j
{
if(strcmp(stud[j].name,stud[j+1].name)>0)
{
temp=stud[j];
stud[j]=stud[j+1];
stud[j+1]=temp;
}
}
}
}
int main(int argc, const char * argv[]) {
// insert code here...
student stu1[4]={{1001,"zhangsan","m",20},
{1002,"lisi","f",21},
{1003,"wangwu","m",19},
{1004,"zhaoliu","f",20}};
int i,len;
len=sizeof(stu1)/sizeof(stu1[0]);
bubble_sort(stu1,len);
for(i=0;i
{
printf("\t%d\t%s\t%s\t%d\t\n",stu1[i].num,
stu1[i].name,stu1[i].sex,stu1[i].age);
}
return 0;
}
運行結果:
總結
以上是生活随笔為你收集整理的c语言简短的泡沫排序法编程,冒泡排序--简单(c语言)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab数据接口技术,matlab接
- 下一篇: android 分享到豆瓣,Androi