#include<stdio.h> #include<conio.h> void sorting(int *x, int y); void main() { int a[20], i, c, n; clrscr(); printf("Enter number of elements you want to sort: "); scanf("%d", &n); for(i = 0; i < n; i++) scanf("%d", &a[i]); sorting(a, n); for(i = 0; i <n; i++) printf("%d\t", a[i]); getch(); } void sorting(int *x, int y) { int i, j, temp; for(i = 1; i <= y-1; i++) { for(j = 0; j < y-i; j++) { if(*(x+j) > *(x+j+1)) { temp = *(x+j); *(x+j) = *(x+j+1); *(x+j+1) = temp; } } } }
Enter number of elements you want to sort: 6
5 3 4 2 1 6
1 2 3 5 6
Linux, PHP, C,C++,JavaScript,verilog 老师
除教程外,本网站大部分文章来自互联网,如果有内容冒犯到你,请联系我们删除!