CSE 130 Fall 2005 Sample Final Exam 1. (10 Points) Identify the error in each of the following code fragments: a. struct stack { int stackSize; struct stackNode *top }; struct stackNode { int value; struct stackNode *next; }; b. int i= 5; int *iPtr= i; c. enum month= { january= 1, february, march, april, may, june }; month m= march; 2. (20 points) Given a linked list whose nodes are defined as follows: struct listNode { float value; struct listNode *next; } typedef struct listNode listNode; and the following global variable declaration: listNode *head= null; /* points to start of list */ Fill in the body of the function below, which creates a new node and adds it to the front of the linked list. void addAtBeginning( float newValue ) { } 3. (15 points) Fill in the body of the findMedian() function below, which takes two arguments: an array of integers and an integer representing the total number of elements in the array. This method should sort the array and then return the middle (median) value in the sorted array. If the array contains an even number of elements, you should return the larger of the two middle values (so, for example, the median of {1, 2, 3, 4} would be 3). You may use any algorithm you wish to sort the array, and you may change the original array; however, you may not lose any values in the process of sorting! int findMedian( int data [], int N ) { } 4. (20 points) A "triangular number" is generated using the following formula: triangle(n) = n * (n+1) / 2 for any integer value of n. For example, the 10th triangular number is 55 (triangle(10) = 55). Write a loop that computes and prints a table of every fifth triangular number between 5 and 50 (that is, the fifth triangular number, the tenth, the fifteenth, etc., up thru the fiftieth). 5. (10 points) Define a time structure that stores the hour, minute, and second in separate integer fields. 6. (10 points) You are given an array with the following contents: {23, 45, 1, 24, 87, 6, 19} We will sort this array using selection sort. Draw the contents of the array after each round of the sorting algorithm. 7. (10 points) Write a function named "exchange" that takes two pointers to floating-point numbers "x" and "y" and does not return a value. The function should swap the contents of x and y.