Advertisement

simple selection sort (C++ implementation)

阅读量:
复制代码
    #include<stdio.h>
    #include<stdlib.h>
    #include<iostream>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<limits>
    #include<algorithm>
    #include<math.h>
    #pragma warning(disable:4996)
    using namespace std;
    
    //每一趟在待排序元素中选取关键字最小的元素加入有序子序列
    //必须进行总共n-1趟处理
    
    //简单选择排序
    void swap(int& a, int& b)//传引用。C++提供了swap函数,可不写
    {
    	int temp = a;
    	a = b;
    	b = temp;
    }
    void SelectSort(int A[], int n)
    {
    	for (int i = 0; i < n - 1; i++) {//一共进行n-1趟
    		int min = i;//记录最小元素位置
    		for (int j = i + 1; j < n; j++

全部评论 (0)

还没有任何评论哟~