国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

改進(jìn)partition 算法代碼

2023-05-26 09:52 作者:算法設(shè)計與分析張老師  | 我要投稿

#include<iostream>?

#include<algorithm>

using namespace std;?

//演示3-way-partition 給定n個數(shù)據(jù),將其按第一個數(shù)據(jù)做分區(qū)中樞

//threep返回兩個數(shù)據(jù),分別為中間段的起始和終止位置下標(biāo)?

// p中間段起始下標(biāo),r是中間段截止下標(biāo)??

void threep(int a[],int &p,int &r)

?{

? int x=a[p];?

? int k=p+1;

? while(k<=r)

? {

? if(a[k]<x)swap(a[k++],a[p++]);

? else if(a[k]>x)swap(a[k],a[r--]);

? else k++;

}

?}

?void quicksort(int a[],int left,int right)

?{

? if(left<right)

? {? int lleft=left,rright=right;

? threep(a, lleft,rright);

? quicksort(a,left,lleft-1);

? quicksort(a,rright+1,right);

}

?}

int main()

{

? int n,p,r;

? cin>>n;

? int a[n];

? for(int i=0;i<n;i++)cin>>a[i];? //5 7 5 2? 5 8

? p=0;r=n-1;

? threep(a,p,r);?

? for(int i=0;i<n;i++)cout<<a[i]<<" ";?

? cout<<"\np="<<p<<"? r="<<r;?

? // quicksort(a,p,r);

? //for(int i=0;i<n;i++)cout<<a[i]<<" ";?

? return 0;

}


改進(jìn)partition 算法代碼的評論 (共 條)

分享到微博請遵守國家法律
伊金霍洛旗| 大丰市| 威远县| 宣城市| 若羌县| 昌黎县| 湘西| 延川县| 福贡县| 栾城县| 台州市| 友谊县| 馆陶县| 比如县| 明水县| 巴彦淖尔市| 东阳市| 三江| 安达市| 邵阳市| 汤原县| 聊城市| 新民市| 那曲县| 阿克陶县| 深圳市| 白城市| 长治市| 桂平市| 巴彦淖尔市| 白朗县| 宁海县| 禄丰县| 敖汉旗| 江永县| 怀来县| 田林县| 松桃| 卢湾区| 辽宁省| 巴彦淖尔市|