Select Sort & Bubble Sort
来源:互联网 发布:windows dock软件 编辑:程序博客网 时间:2024/06/06 05:52
// Select_sort.c.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
using namespace std;
void select_sort(int a[],int n)
{
int temp;
for(int i=0;i<n-1;++i){
int j=i;
for(int k=i+1;k<n;++k)
if(a[k]<a[j])j=k;
if(j!=i){temp=a[j];a[j]=a[i];a[i]=temp;}
}
}
void bubble_sort(int a[],int n)
{
bool change=true;
for(int i=n-1;i>1&&change;--i){
change=false;
for(int j=0;j<i;++j)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
change=true;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int b[]={10,2,2,15,9,88,7};
//select_sort(b,7);
//for(int out=0;out<7;++out)
// cout<<b[out]<<endl;
//system("pause");
bubble_sort(b,7);
for(int out=0;out<7;++out)
cout<<b[out]<<endl;
system("pause");
return 0;
}
//
#include "stdafx.h"
#include "iostream"
using namespace std;
void select_sort(int a[],int n)
{
int temp;
for(int i=0;i<n-1;++i){
int j=i;
for(int k=i+1;k<n;++k)
if(a[k]<a[j])j=k;
if(j!=i){temp=a[j];a[j]=a[i];a[i]=temp;}
}
}
void bubble_sort(int a[],int n)
{
bool change=true;
for(int i=n-1;i>1&&change;--i){
change=false;
for(int j=0;j<i;++j)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
change=true;
}
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int b[]={10,2,2,15,9,88,7};
//select_sort(b,7);
//for(int out=0;out<7;++out)
// cout<<b[out]<<endl;
//system("pause");
bubble_sort(b,7);
for(int out=0;out<7;++out)
cout<<b[out]<<endl;
system("pause");
return 0;
}
0 0
- Select Sort & Bubble Sort
- Bubble sort
- Bubble Sort
- bubble sort
- Bubble Sort
- Bubble Sort
- bubble sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- Bubble sort
- Bubble Sort
- Bubble Sort
- Bubble Sort
- android中MessageQueue , Message , Looper , Handler(三)
- .NET Core与.NET Framework、Mono之间的关系
- powerdesigner 物理模型导出sql(mysql),将name添加为注释的方法
- Linux基础目录处理命令 mkdir cd pwd rm cp mv
- 并查集 学习笔记
- Select Sort & Bubble Sort
- String,StringBuffer,StringBuilder的区别
- Android 中消息处理机制-Looper、Handler、Thread (二)
- ios中UIView常见的一些方法介绍及使用
- JAVA学习笔记之(Socket)
- leetcode题解
- ADB安装软件以及传输文件
- 3.5 垃圾收集器
- ExtJs刷新页面的方法