//
// main.c
// BubbleSort
//
// Created by Wuyixin on 2017/6/2.
// Copyright © 2017年 Coding365. All rights reserved.
//
#include <stdio.h>
void bubbleSort(int a[],int n){
int i,j;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i; j++) {
if (a[j] > a[j + 1]){
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
int main(int argc, const char * argv[]) {
int a[] = {9,3,1,4,7,6,5,8,2};
bubbleSort(a, 9);
int i = 0;
while (i < 9)
printf("%d ",a[i++]);
return 0;
}
//
// main.c
// SelectionSort
//
// Created by Wuyixin on 2017/6/2.
// Copyright © 2017年 Coding365. All rights reserved.
//
#include <stdio.h>
void selectionSort(int a[],int n){
int i,j,min,temp;
for (i = 0; i < n; i++) {
min = i;
for (j = i + 1; j < n; j++) {
if (a[j] < a[min])
min = j;
}
if (i != min){
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
int main(int argc, const char * argv[]) {
int a[] = {9,3,1,4,7,6,5,8,2};
selectionSort(a, 9);
int i = 0;
while (i < 9)
printf("%d ",a[i++]);
return 0;
}
//
// main.c
// InsertionSort
//
// Created by Wuyixin on 2017/6/2.
// Copyright © 2017年 Coding365. All rights reserved.
//
#include <stdio.h>
void insertionSort(int a[],int n){
int i,j,temp;
for (i = 1; i < n ; i++) {
temp = a[i];
for (j = i; j > 0 && temp < a[j - 1]; j--) {
a[j] = a[j - 1];
}
a[j] = temp;
}
}
int main(int argc, const char * argv[]) {
int a[] = {9,3,1,4,7,6,5,8,2};
insertionSort(a, 9);
int i = 0;
while (i < 9)
printf("%d ",a[i++]);
return 0;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有