코드
#include <iostream>
using namespace std;
void InsertionSort(char* A, int n) {
char cur;
for (int i=0;i<n;i++) {
cur = A[i];
int j = i-1;
while (j>=0 && cur < A[j]) {
A[j+1] = A[j]; // Move A[j] right
j--;
}
A[j+1] = cur;
}
}
int main (void) {
char A[10] = {'B', 'C', 'F', 'Z', 'E', 'A', 'S', 'J', 'U', 'Y'};
InsertionSort(A, 10);
for (int i=0;i<10;i++) {
cout << A[i] << " ";
}
cout << endl;
return 0;
}
/// 실행결과 : A B C E F J S U Y Z