前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >冒泡和选择排序

冒泡和选择排序

作者头像
ternturing
发布2018-09-12 17:34:23
3590
发布2018-09-12 17:34:23
举报
文章被收录于专栏:炉边夜话

#include <stdio.h> #include <stdlib.h> #include <string.h> //冒泡排序 void bubbleSort(int *a,int len) {      int i,j,temp;      for(i = 0;i<len-1;i++)      {           for(j=0;j<len -i-1;j++)           {                if(a[j]>a[j+1])                {                    temp=a[j];                    a[j]=a[j+1];                    a[j+1]=temp;                }          }     } } //选择排序 void selectSort(int *a,int len) {      int i,j,temp,result;      for(i=0;i<len-1 ;i++)      {           temp=i;           for(j=i+1;j<len-1;j++)           {                 if(a[j]<a[temp])                 {                        temp=j;                 }          }          if(temp!=i)           {                result=a[i];                a[i]=a[temp];                a[i]=result;           }       } }

void print(int *a,int len) {     int i=0;     for(i=0;i<len;i++)     {         printf("%d ",a[i]);     }     printf("/n"); }

int main() {     int value[10]={38,6,14,9,7,33,67,12,34,51};     printf("bubbleSort result:/n");     bubbleSort(value,10);     print(value,10);     printf("bubbleSort result:/n");     selectSort(value,10);     print(value,10);     return 0;

}

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2006年06月19日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档