Exemplo n.º 1
0
void quick_sort1(int *array, int length)
{
    int i = 0;
    int j = length - 1;
    int value = 0;
    if(length > 1){
        value = array[0];
        while(i < j){
            while(i < j && array[j] >=value){
                j--;
            }
            if(array[j] < value){
                array[i++] = array[j];
            }
            while(i < j && array[i] <= value){
                i++;
            }
            if(array[i] > value){
                array[j--] = array[i];
            }
        }
        array[i] = value;
        quick_sort1(array, i);
        quick_sort1(array + i + 1, length - i -1);
    }
}
Exemplo n.º 2
0
int main(void)
{
    int a[NUM];
    srand(time(NULL));
    for (int i=0; i<NUM; i++) {
        a[i] = rand() % 100;
        printf("%d ", a[i]);
    }
    printf("\n");
    quick_sort1(a, 0, NUM-1);
    for (int i=0; i<NUM; i++)
        printf("%d ", a[i]);
    printf("\n");
    check(a,NUM);
    printf("\n");
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char const *argv[])
{
    std::vector<int> s;
    s.push_back(10);
    s.push_back(4);
    s.push_back(23);
    s.push_back(3);
    s.push_back(7);
    s.push_back(19);
    //quick_sort(s, 0, 5);

    quick_sort1(s, 0, 5);
    for (int i = 0; i < 6; ++i)
    {
    	std::cout << s[i] << std::endl;
    }

	return 0;
}