• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

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

20.02.17 15:04 작성 조회수 162

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;

}

답변 1

답변을 작성해보세요.

0

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