강의

멘토링

커뮤니티

Inflearn Community Q&A

jyk23670961's profile image
jyk23670961

asked

Following and Learning C++ with Hong Jeong-mo

6.4 Array and selection sort

버블정렬 짜봤는데 더 좋은방법 있나요?

Written on

·

249

1

#include <iostream>

using namespace std;

void printArray(const int array[],const int length)

{

for (int index = 0; index < length; ++index)

{

cout << array[index] << " ";

}

cout << endl;

}

int main(void)

{

const int lengthe = 5;

int array0[lengthe] = { 3,5,2,1,4 };

int max = 0;

for (int reset = 0; reset < lengthe; reset++) 

{

for (int i = 0, j = 1; (i < lengthe - 1) && (j < lengthe); j++, i++)

{

if (array0[i] <= array0[j])

continue;

else if (array0[i] > array0[j]) 

{

temp = array0[i];

array0[i] = array0[j];

array0[j] = temp;

}

printArray(array0, lengthe);

}

}

return 0;

}

C++

Answer 1

0

honglab님의 프로필 이미지
honglab
Instructor

자료구조 과목에서 정렬에 대해 더 자세히 배우시게 될겁니다.

jyk23670961's profile image
jyk23670961

asked

Ask a question