Previous: 10.7 Summary
Up: 10 Sorting and Searching
Next: 10.9 Problems
Previous Page: 10.7 Summary
Next Page: 10.9 Problems

10.8 Exercises

Find and correct errors if any.

  1. main()
    {    int x[10];
    

    x[10] = {12, 23, 45}; }

  2. main()
    {    int x[10];
    

    x = {12, 23, 45}; }

  3. main()
    {    int i, x[10];
    

    for (i = 0; i < 10; i++) x = 0; }

  4. Should you use a function or a macro to swap values in bubble sort? Explain your reasons.

  5. Bubble sort moves the largest value to the highest index. Modify the bubble sort code to move the smallest element to the lowest index.

  6. Insertion sort inserts a new element into the array. Modify the insertion sort method to apply it to an unsorted array with n elements. Do not use another array.

  7. Modify the bubble sort to apply it to an array of characters housing a string. The number of elements in the string are unknown, but terminated by a NULL.

tep@wiliki.eng.hawaii.edu
Sat Sep 3 06:58:41 HST 1994