278 Arrays Chapter 7 As the turtle moves (Cedant web hosting)
Wednesday, October 3rd, 2007278 Arrays Chapter 7 As the turtle moves with the pen down, set the appropriate elements of array floorto 1s. When the 6 command (print) is given, wherever there is a 1in the array, display an asterisk or another character. Wherever there is a zero, display a blank. Write a program to implement the turtle graphics capabilities we have discussed. Write several turtle graphics programs to draw interesting shapes. Add commands to increase the power of your turtle graphics language. SPECIAL SECTION: RECURSION EXERCISES 7.7 (Palindromes) A palindrome is a string that is spelled the same forward and backward. Some examples of palindromes are radar, able was i ere i saw elba and, if blanks are ignored, a man a plan a canal panama. Write a recursive method testPalindrome that returns true if the string stored in the array is a palindrome and false otherwise. The method should ignore spaces and punctuation in the string. 7.8 (Linear Search) Modify Fig. 7.11 to use recursive method LinearSearch to perform a linear search of the array. The method should receive an integer array and the size of the array as arguments. If the search key is found, return the array subscript; otherwise, return 1. 7.9 (Binary Search) Modify the program in Fig. 7.12 to use a recursive method Binary- Search to perform the binary search of the array. The method should receive an integer array and the starting and ending subscript as arguments. If the search key is found, return the array subscript; otherwise, return 1. 7.10 (Quicksort) In this chapter, we discussed the sorting technique bubble sort. We now present the recursive sorting technique called Quicksort. The basic algorithm for a single-subscripted array of values is as follows: a) Partitioning Step. Take the first element of the unsorted array and determine its final location in the sorted array (i.e., all values to the left of the element in the array are less than the element, and all values to the right of the element in the array are greater than the element). We now have one element in its proper location and two unsorted subarrays. b) Recursive Step. Perform step 1 on each unsorted subarray. Each time Step 1 is performed on a subarray, another element is placed in its final location of the sorted array, and two unsorted subarrays are created. When a subarray consists of one element, it must be sorted; therefore, that element is in its final location. The basic algorithm seems simple, but how do we determine the final position of the first element of each subarray? Consider the following set of values (partitioning element in bold it will be placed in its final location in the sorted array): 37 2 6 4 89 8 10 12 68 45 a) Starting from the rightmost element of the array, compare each element to 37 until an element less than 37 is found, then swap 37 and that element. The first element less than 37 is 12, so 37 and 12 are swapped. The new array is 12 2 6 4 89 8 10 37 68 45 Element 12 is italicized to indicate that it was just swapped with 37. b) Starting from the left of the array, but beginning with the element after 12, compare each element to 37 until an element greater than 37 is found, then swap 37 and that element. The first element greater than 37 is 89, so 37 and 89 are swapped. The new array is 12 2 6 4 37 8 10 89 68 45
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.