#include <iostream>
using namespace std;
void printArray(const int array[],const int length) // const 변수 바꿀 수 x
{
for (int index = 0; index < length; ++index)
cout << array[index] << " ";
cout << endl;
}
int main()
{
const int length = 5;
int array[length] = { 3,5,2,1,4, };
printArray(array, length);
for (int startIndex = 0; startIndex < length - 1; ++startIndex)
{
int smallestIndex = startIndex;
for (int currentIndex = startIndex + 1; currentIndex < length; ++currentIndex)
{
if (array[smallestIndex] > array[currentIndex])
{
smallestIndex = currentIndex;
}
}
//swap to values in the array
{
int temp = array[smallestIndex];
array[smallestIndex] = array[startIndex];
array[startIndex] = temp;
}
}
return 0;
}
*어려움 ㅜㅜ
debug 찍어서 바뀌는거 보고 복습하기
'programming > c++' 카테고리의 다른 글
6.7 포인터 기본 (0) | 2020.01.26 |
---|---|
6.5 정적 다차원 배열 (0) | 2019.05.06 |
6.3 배열과 반복문 (0) | 2019.05.06 |
6.1 배열 기초적인 사용법 (0) | 2019.05.06 |
5.9 난수 만들기 (0) | 2019.05.04 |