c语言数据结构-------------交换排序

#include 

void swap(int *, int *);
int Partition(int A[], int low, int high);
//冒泡排序
void BubbleSort(int A[], int n) {
    for (int i = 0; i < n - 1; ++i) {
        int flag = 0;


        for (int j = 0; j < n - i - 1; ++j) {
            if (A[j] > A[j + 1]) {
                swap(&A[j], &A[j + 1]);
                flag++;
            }
        }
        if (flag == 0) {
            break;
        }

    }
}

void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}

void QuickSort(int A[], int low, int high) {
    if (low < high) {

        int pivotpos=Partition(A,low,high);

        QuickSort(A,low,pivotpos-1);
        QuickSort(A,pivotpos+1,high);


    }
}
int Partition(int A[], int low, int high) {
     int pivot=A[low];

     while(low=pivot)  high--;

         A[low]=A[high];

         while (low 
 

你可能感兴趣的:(数据结构,c语言,算法)