STUFF TO STUDY: -------------- We did a lot of drill in Office Hours today. Stuff that might be good to work out, and see if you can do it -- good practice for the exam: You will have to write functions on the exam. Write functions to perform the tasks below. You should be able to do all of them. Don't write them all with as arrays as parameters; Make some of the parameters pointers instead. You should be able to do both. A. Linear Search ---------------- Given: a sorted array with size N. Find a value x stored in the array. Print "Found" if it's there and "Not Found" if it isn't. In a linear search, you start at one end of the array and walk to the other end. If you get to the end and it's not there, it is "NOT FOUND". If you find it along the way, you're done, it's "FOUND". B. Binary Search ---------------- Same goal as above. Only the way you perform the search is different. For a Binary search, you divide your working array into two pieces. If you're greater than the middle element, you look in the lower half of the array. If you're bigger than the middle element, you look in the upper half. Continue in this manner until you find it or you Know it's not there. When do you know it's not in the array in a Binary Search? C. Find the biggest element in an UNSORTED array ------------------------------------------------- D. Find the smallest element in an unsorted array ------------------------------------------------- E. Find the third smallest element in an unsorted array -------------------------------------------------------- F. Write a swap function ------------------------- This takes two ints -- by "reference" and will swap their values. G. Reverse an array in place ----------------- given an array c: for example: if your then your Starting Array | Finished Array looks like this | looks like this -------------------|----------------------- c[0] = 1 | c[0] = 5 c[1] = 2 | c[1] = 4 c[2] = 3 | c[2] = 3 c[3] = 4 | c[3] = 2 c[4] = 5 | c[4] = 1 Your reverse the values in the array -- you have to be careful. Hint: You need to store the old value in a temporary before you swap. You can use the swap function in #6. H. Sum, Increase and Decrease ----------------------------- Given 3 arrays of the same size: a, b, and c. You want the cells in c to equal the sum of the same cells in a + b After you sum, you want to: a) increase the value in a by 1 and b) decrease the value in b by 1. I. Odds and Evens ------------------ Given an array: Put all the odd values in the front half of the array. Put all the even values in the back half.