<div>#include <cstdio></div> <div>#include <cstdlib></div> <div>#include <cstring></div> <div><br></div> <div>inline int ascend(int x, int y) { return y - x; }</div> <div>inline int descend(int x, int y) { return x - y; }</div> <div><br></div> <div>void insertionSort(int A[], int n, int(*f)(int, int))</div> <div>{</div> <div><span style="white-space:pre;"> </span>for (int i = 1; i < n; i++)</div> <div><span style="white-space:pre;"> </span>{</div> <div><span style="white-space:pre;"> </span>int key = A[i];</div> <div><span style="white-space:pre;"> </span>int j;</div> <div><span style="white-space:pre;"> </span>for (j = i - 1; j >= 0 && f(A[j], key); j--)</div> <div><span style="white-space:pre;"> </span>A[j + 1] = A[j];</div> <div><span style="white-space:pre;"> </span>A[j + 1] = key;</div> <div><span style="white-space:pre;"> </span>}</div> <div>}</div> <div><br></div> <div>static void initRandom(int list[], int n, int max = 100)</div> <div>{</div> <div><span style="white-space:pre;"> </span>for (int i = 0; i < n; i++)</div> <div><span style="white-space:pre;"> </span>list[i] = rand() % max;</div> <div>}</div> <div><br></div> <div>static void printArray(int arr[], int n, const char* str = "Array")</div> <div>{</div> <div><span style="white-space:pre;"> </span>printf("%s = ", str);</div> <div><span style="white-space:pre;"> </span>for (int i = 0; i < n; i++)</div> <div><span style="white-space:pre;"> </span>printf("%3d", arr[i]);</div> <div><span style="white-space:pre;"> </span>printf("\n");</div> <div>}</div> <div><br></div> <div>int main(void)</div> <div>{</div> <div><span style="white-space:pre;"> </span>int list[16];</div> <div><span style="white-space:pre;"> </span>int n = 16;</div> <div><span style="white-space:pre;"> </span>initRandom(list, n);</div> <div><span style="white-space:pre;"> </span>printArray(list, n, "Original ");</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>memcpy(list, org, n * sizeof(int));</div> <div><span style="white-space:pre;"> </span>insertionSort(list, n, ascend);</div> <div><span style="white-space:pre;"> </span>printArray(list, n, "Insert-As");</div> <div><br></div> <div><span style="white-space:pre;"> </span>memcpy(list, org, n * sizeof(int));</div> <div><span style="white-space:pre;"> </span>insertionSort(list, n, descend);</div> <div><span style="white-space:pre;"> </span>printArray(list, n, "Insert-De");</div> <div><span style="white-space:pre;"> </span>return 0;</div> <div>}</div> <div><br></div> <div>책에 나와있는대로 그대로 옮겨 적었는데요</div> <div>메인함수에 첫번째 memcpy(list, org, n * sizeof(int)) 부분에서 org부분이 </div> <div>[C2065] org : 선언되지 않는 식별자 입니다.</div> <div>라고 나오는데 어떻게 해야 되나요? ㅠㅠ</div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.