bubble sort
1 // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。 2 // 3 4 #include "stdafx.h" 5 #include <stdio.h> 6 #include <iostream> 7 using namespace std; 8 void Print(int*num, int n) 9 { 10 int i; 11 for (i = 0; i < n; i++) 12 printf("%d ", num[i]); 13 puts("\n"); 14 return; 15 } 16 void Bubble_sort(int *num, int n){ 17 int i, j; 18 for (i = 0; i < n; i++) 19 { 20 for (j = 0; i+j < n-1; j++){ 21 if (num[j]>num[j+1]){ 22 int temp = num[j]; 23 num[j] = num[j+1]; 24 num[j+1] = temp; 25 } 26 27 } 28 Print(num, n); 29 } 30 } 31 int _tmain(int argc, _TCHAR* argv[]) 32 { 33 int a; 34 int x[7] = { 31,65,82,76,13,27,10 }; 35 Bubble_sort(x, 7); 36 //Print(x, 7); 37 cin >> a; 38 return 0; 39 40 }