From f47031fb3c2f9c721348e423d218c33bdd20110e Mon Sep 17 00:00:00 2001 From: Liuhua Date: Fri, 12 May 2023 03:01:38 +0000 Subject: [PATCH] =?UTF-8?q?CI=20BOT=E6=B5=8B=E8=AF=95=E5=8D=95=EF=BC=8C?= =?UTF-8?q?=E8=AF=B7=E5=8B=BF=E5=90=88=E5=85=A5!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Liuhua --- test0512.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test0512.c diff --git a/test0512.c b/test0512.c new file mode 100644 index 0000000..0673676 --- /dev/null +++ b/test0512.c @@ -0,0 +1,17 @@ +//对区间[left,right]进行划分 +int Partition(int A[],int left, int right) +{ + int temp =A[left]; //存放到临时变量temp + + while(left < right) //只要left与right不相遇 + { + while(left < right && A[right] > temp) right--;//反复左移 + A[left] = A[right]; + + while(left < right && A[left] <= temp) left++;//反复右移 + A[right] = A[left]; + } + + A[left] = temp; //把temp放到right与left相遇的地方 + return left; //返回相遇下标 +} -- Gitee