KakaoTalk_20190606_001802318.png
  • 246x0w
Welcome
Curriculum
Install&Go
Board
실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
  • 카테고리
  • 전체 게시물
  • 내 게시물
im020526
2020년 4월 08일

200408

게시판: 소스 코드 제출

/*

#include <iostream>

using namespace std;

int main()

{

int n,a[1001],b[1001],c[1001],temp;

cin>>n;

for(int i=0; i<n; i++)

{

cin>>a[i]>>b[i];

}

for(int i=1; i<=n; i++)

{

c[i-1]=i;

}

for(int i=0; i<n; i++)

{

for(int j=0; j<n-1; j++)

{

if(a[j] < a[j+1])

{

temp = a[j];

a[j] = a[j+1];

a[j+1] = temp;

temp = b[j];

b[j] = b[j+1];

b[j+1] = temp;

temp = c[j];

c[j] = c[j+1];

c[j+1] = temp;

}

}

}

for(int i=0; i<n; i++)

{

for(int j=0; j<n-1; j++)

{

if(a[j] < a[j+1] && b[j] < b[j+1])

{

temp = b[j];

b[j] = b[j+1];

b[j+1] = temp;

temp = a[j];

a[j] = a[j+1];

a[j+1] = temp;

temp = c[j];

c[j] = c[j+1];

c[j+1] = temp;

}

else if(a[j] == a[j+1] && b[j] < b[j+1])

{

temp = b[j];

b[j] = b[j+1];

b[j+1] = temp;

temp = a[j];

a[j] = a[j+1];

a[j+1] = temp;

temp = c[j];

c[j] = c[j+1];

c[j+1] = temp;

}

}

}

for(int i=0; i<n; i++)

{

cout<<c[i]<<' '<<a[i]<<' '<<b[i]<<'\n';

}

}

*/

#include <iostream>

#include <string.h>

#include <stdio.h>

using namespace std;

void Swap(int arr[], int idx1, int idx2)

{

int temp = idx1;

idx1 = idx2;

idx2 = temp;

}


int partition(int arr[], int left, int right)

{

int p = arr[0];

int low = arr[1];

int high = arr[sizeof(arr)/sizeof(int)-1];


while(low > high)

{

if(low >= p)

{

Swap(arr,low,high);

}

else if(high <= p)

{

Swap(arr,high,low);

}

low++;

high--;

cout<<'*';

Swap(arr,high,low);

}

Swap(arr,high,p);

}


void Quicksort(int arr[], int left, int right)

{

for(int i=0; i<7; i++)

{

if(arr[left] > arr[right])

{

partition(arr,left+1,right);

}

left++;

right--;

}

}


int main(void)

{

int arr[7]={3,2,4,1,7,6,5};

//int arr[3]={3,3,3};


int len = sizeof(arr) / sizeof(int);

int i;


Quicksort(arr, 0, sizeof(arr)/sizeof(int)-1);


for(int i=0; i<len; i++)

cout<<arr[i]<<'\n';

}


댓글 0개
0
댓글
댓글 0개
유사 게시물
  • 220807
  • 20220807
  • 20220807
주소 : 경기도 용인시 광교중앙로 302 블루 스퀘어 602호
연락처 : 031) 216 - 1546
사업자등록번호 : 465-92-00916
​학원 등록 제 4603호