卷別
資料結構
選擇國立中央大學 2026 · 考試 · 第 43 題
The memmove function is declared in the <string.h> header file in C, and the <cstring> header file in C++. The function prototype is:
void *memmove(void *dest, const void *src, size_t count);
It copies count bytes from the src memory to the dest memory area, safely handling cases where the source and destination regions overlap. Its speed is generally excellent and optimized by compiler/hardware. The following code provides fast Insertion operation using both Binary Search and memmove. Which of the following statements is the least accurate?
1 void insert(int arr[], int n, int key) {
2 int j;
3 if (n<=0){
4 j=0;
5 }
6 else{
7 j=binary_search(arr,key,0,n-1);
8 }
9 if ((n-j)>0) {
10 memmove(arr+j+1,arr+j,(n-j)*sizeof(int));
11 }
12 arr[j]=key;
13 }
- (A)It is stable.
- (B)It is in-place.
- (C)Computation complexity is O(n log n)
- (D)Binary search has O(log n) computational complexity
- (E)The insertion operation in an array using
memmovecan be as efficient as that of a linked list, provided there is optimized hardware support.