ÓãCÂÛ̳

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á
²é¿´: 1876|»Ø¸´: 4

C++ ¿ìËÙÅÅÐò µÄÎÊÌ⣡£¡£¡£¡ÇóÖúÇóÖú¡£

[¸´ÖÆÁ´½Ó]
·¢±íÓÚ 2020-3-29 00:13:19 | ÏÔʾȫ²¿Â¥²ã |ÔĶÁģʽ

ÂíÉÏ×¢²á£¬½á½»¸ü¶àºÃÓÑ£¬ÏíÓøü¶à¹¦ÄÜ^_^

ÄúÐèÒª µÇ¼ ²Å¿ÉÒÔÏÂÔØ»ò²é¿´£¬Ã»ÓÐÕ˺ţ¿Á¢¼´×¢²á

x
±¾Ìû×îºóÓÉ Ê®¶þÔµÄÏô°î ÓÚ 2020-3-30 13:13 ±à¼­

ºÍ¼×Óã¸çÄǸö¿ìËÙÅÅÐòºÃÏñÓеãÇø±ð£¿£¿£¿

ÒªÇóÓõ½Èý¸öº¯Êý£º

void quicksort( int * const, int, int );
int partition( int * const, int, int );
void swap( int * const, int * const );

quicksortÊǵݹ麯Êý£¬µ÷ÓÃpartitionº¯Êý½øÐзÖÇø¡£


û̫Àí½âÓÃÈý¸öº¯ÊýÕâÑùÔõô×ö£¬Ð´ÁËÒ»°ë²»»áÁË£¬²»ÖªµÀ˼·¶Ô²»¶Ô¡£
Çó½â´ð¡£

ÎÒдµÄÈçÏ£º





#include<iostream>
using namespace std;

void quickSort(int* const, int, int);
int partition(int* const, int, int);
void swap(int&,int&);



void quickSort(int* const a, int left, int right)
{
        if (left >= right)return;
        int pivot = partition(a, left, right);

        quickSort(a, left, pivot - 1);
        quickSort(a, pivot + 1, right);

}



int partition(int* const a, int l, int r)//¶Ô´Óa[l]µ½a[r]µÄÊý×飬ÕÒµ½a[l]µÄλÖ㬲¢·µ»ØlµÄÖµ
{

        while (l < r)
        {


               
        }

        return l;
}



void swap(int &x,int &y)
{
        int temp = x;
        x = y;
        y = temp;

}
       


int main()
{
        int a[10] = { 6,5,8,9,10,1,4,3,2,7 };
        void printarray(int[]);
       

        cout << "Before:\n";
        printarray(a);


        quickSort(a, 0, 9);


        cout << "\nAfter:\n";
        printarray(a);

       
       

        return 0;
}


void printarray(int a[])
{

        for (int i = 0; i < 10; ++i)
        {
                cout.width(4);
                cout << a[i];

        }

}
JW2TTXZ)APAIHFW{8HM}3G9.png
TNDC1Z`J$C0DRI7SHN$JSP7.png
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
 Â¥Ö÷| ·¢±íÓÚ 2020-3-29 14:24:14 | ÏÔʾȫ²¿Â¥²ã
¶¥Ò»ÏÂ
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
 Â¥Ö÷| ·¢±íÓÚ 2020-3-30 13:10:26 | ÏÔʾȫ²¿Â¥²ã
ÔÙ¶¥Ò»ÏÂ
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
·¢±íÓÚ 2020-3-30 16:09:53 | ÏÔʾȫ²¿Â¥²ã

»ØÌû½±Àø +2 Óã±Ò

¸Ð¾õswapº¯ÊýÓеã¶àÓà
#include <stdio.h>

int partition(int k[], int low, int high) {
    int key = k[low];
    while(low < high) {
        while(low < high && key <= k[high])
            --high;
        k[low] = k[high];
        while(low < high && key >= k[low])
            ++low;
        k[high] = k[low];
    }
    k[low] = key;
    return low;
}

void qsort(int k[], int low, int high) {
    if(low >= high) return;
    int point = partition(k, low, high);
    qsort(k, low, point - 1);
    qsort(k, point + 1, high);
}

int main(void) {
    int a[10] = {4, 2, 5, 0, 3, 9, 1, 7, 6, 8};
    qsort(a, 0, 9);
    for(int i = 0; i < 10; ++i) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return 0;
}
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
·¢±íÓÚ 2020-3-30 16:10:30 | ÏÔʾȫ²¿Â¥²ã
ÏëÖªµÀС¼×Óã×î½üÔÚ×öɶ£¿Çë·ÃÎÊ -> ilovefishc.com
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼ | Á¢¼´×¢²á

±¾°æ»ý·Ö¹æÔò

СºÚÎÝ|ÊÖ»ú°æ|Archiver|ÓãC¹¤×÷ÊÒ ( ÔÁICP±¸18085999ºÅ-1 | ÔÁ¹«Íø°²±¸ 44051102000585ºÅ)

GMT+8, 2025-1-15 17:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí