It looks like your code has several issues, including missing semicolons, incorrect function declarations, and incomplete implementation of the `shellsort` function. Let's correct and complete the code step by step. Corrected and Complete Code ```cpp #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int n = 10; const int min = 10; const int max = 99; // Function to generate a random number between min and max int getrand(int min, int max) { return (rand() % (max - min + 1) + min); } // Function to initialize the array with random numbers void set(int r[], int n) { for (int i = 0; i < n; i++) { r[i] = getrand(min, max); } } // Function to display the array void show(int r[], int n) { for (int i = 0; i < n; i++) { cout << r[i] << " "; } cout << endl; } // Function to perform Shell Sort and display each pass void shellsort(int r[], int n) { for (int gap = n / 2; gap > 0; gap /= 2) { for (int i = gap; i < n; i++) { int temp = r[i]; int j; for (j = i; j >= gap && r[j - gap] > temp; j -= gap) { r[j] = r[j - gap]; } r[j] = temp; } // Display the array after each pass show(r, n); } } int main() { srand(time(0)); int a[n]; set(a, n); cout << "原序列: "; show(a, n); cout << "新序列: \n"; shellsort(a, n); return 0; } ``` Explanation 1. Random Number Generation: - The `getrand` function generates a random number between `min` and `max`. 2. Array Initialization: - The `set` function initializes an array with random numbers generated by `getrand`. 3. Array Display: - The `show` function displays the elements of the array. 4. Shell Sort: - The `shellsort` function performs the Shell Sort algorithm. It starts with a large gap and reduces the gap by half in each iteration until the gap is 1. After each pass, it displays the current state of the array. 5. Main Function: - The `main` function initializes the random number generator, creates an array, initializes it with random numbers, displays the original array, and then sorts the array using the `shellsort` function, displaying the array after each pass. This code should compile and run correctly, showing the original array and the sorted array after each pass of the Shell Sort algorithm. [2024-10-31 11:13:09 | AI写代码神器 | 638点数解答]