免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
FindKthelement

#include <iostream>

#include<stdlib.h>

#include<fstream>

using namespace std;

int temp;int i,j;

void print(ofstream &write,int *a){

     write<<endl;

    for(int i=0;i<10;i++){

write<<a[i]<<' ';

    }

    write<<endl;

}

int FindKthelement(ofstream &write,int *a,int left,int right,int k){

int judge=a[left];i=left;left++;j=right;

print(write,a);

write<<"Moss: u have just made a recursion.This time left="<<left<<" right="<<right<<" k="<<k<<" judge="<<judge<<" i="<<i<<" j="<<j<<endl;

while(1){

while(a[left]<=judge){left++;}

while(a[right]>judge){right--;}

if(right>left){write<<"switch "<<a[left]<<" and "<<a[right]<<endl;temp=a[left];a[left]=a[right];a[right]=temp;}

else {break;}

}

write<<"break: left is "<<left<<" while right is "<<right<<endl;

if(k==left){return judge;}

else if(k<=left){temp=a[left-1];a[left-1]=a[i];a[i]=temp;right=left-2;write<<"choose the left.";FindKthelement(write,a,i,right,k);}

else{temp=a[left-1];a[left-1]=a[i];a[i]=temp;write<<"choose the right.";FindKthelement(write,a,right+1,j,k);}

}

int main()

{

    int a[10]={4,9,0,1,2,6,5,8,3,7};

//               4 3 0 1 2 6 5 8 9 7

ofstream write;

write.open("Findkthelement.txt");

write<<FindKthelement(write,a,0,9,10);

//int a[3]={5,9,1};

//write<<FindKthelement(a,0,2,2,3);

 //                0 1 2 3 4 5 6 7 8 9

//                {4,9,0,1,2,6,5,8,3,7};

//                 4 3 0 1 2 6 5 8 9 7

   return 0;

}

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
隨機(jī)選擇算法
消除文法的左遞歸
幾種C++排序算法的實(shí)現(xiàn)(冒泡,歸并,快速,插入,選擇)
排序算法總結(jié)
102 LeetCode Online Judge 題目C# 練習(xí)Binary Tree Level Order Traversal
圖像處理-05-浮雕效果處理
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服