c++ 선택문에서 조건을 어디에 넣어야 할지 모르겠습니다.ㅠㅠ
조회수 376회
include
using namespace std;
define LENGTH 6
void InsertionSort(int* A) {
for (int j = 1; j < LENGTH; j++)
{
int key = A[j]; //Insert A[j] into the sorted sequence A[0..j-1]
int i = j - 1;
while ((i >= 0) && (A[i] > key))
{
A[i + 1] = A[i];
i--;
}
A[i + 1] = key;
}
}
void Input(int* A)
{
cout << "Input" << LENGTH << "number : " << "\n";
for (int i = 0; i < LENGTH; i++)
cin >> A[i];
}
void Output(int* A)
{
cout << "Result : " << LENGTH << "numbers : " << "\n";
for (int i = 0; i < LENGTH; i++)
cout << A[i] << " ";
cout << "\n";
}
int main()
{
int A[LENGTH] = { 0 };
Input(A);
InsertionSort(A);
Output(A);
return 0;
}
위 코드를 실행하면 숫자 6개를 넣어 오름차순으로 숫자가 배열되는데
선택문으로 1.오름차순 또는 2.내림차순를 선택하는 것에따라 결과값이 나오게 하려면 어디에 조건을
넣어야 할지 모르겠네요 ㅠㅠ
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력