CS140--Homework 5

Note that the function header for problem 5 has changed!!! You are now passed both a pointer to the list and a pointer to the node to be deleted.

  1. Suppose you are given the following declarations:
          Jval val;
          int age;
          double salary;
          char *name;
          struct node *ptr;
          
    1. Write a statement that assigns the variable age to val
    2. Write a statement that assigns the variable salary to val
    3. Write a statement that assigns the variable name to val
    4. Write a statement that assigns the variable ptr to val
    5. Write a statement that assigns the value in val to ptr

  2. Write a union that contains an integer field named age, a pointer to a character string named address, and a three element integer array named test_scores.

  3. The personnel department at State University has to keep track of three types of people: students, professors, and staff. The information it must keep about these groups is as follows:

    1. All three groups of people have an integer social security number, a name of at most 20 characters, and a single character code that denotes whether they are male or female.

    2. Students have a floating point gpa, a floating point fee balance, and a pointer to a list of courses they are taking. The pointer points to a struct course node.

    3. Professors have a floating point salary, a single character code that denotes their rank, a 10 character string that denotes their office, and a pointer to a list of courses they are teaching. The pointer points to a struct course node.

    4. Staff have a floating point hourly rate, an integer that denotes their job classification, and a 10 character string that denotes their office.

  4. You are given a linked list, L, and another linked list, P, containing integers sorted in ascending order. You are to write a function named extract_list that will find the elements in L that are in the positions specified by P and copy their contents to a new list that you will create and return to the user. For example, if P = 1, 3, 4, 6, the first, third, fourth, and sixth elements of L will be copied to the new list. Your function should return a pointer to the new list. Use Dr. Plank's sllist library to represent your linked lists. To copy an element you will simply need to copy the val field to your new list. Since the elements of P are sorted you should only have to make one pass through L in order to create your new list. You do not have to compile or run your program. Just make a good faith effort to write the program. If you want to test your program you can find the sllist.h and .c files in ~cs140/www-home/spring-2005/notes/Sllists.

  5. Write a function called sll_delete_node that deletes a node from an Sllist. You should use the book's solution of keeping a pointer to the previous node as you search the list for the node to delete. Here is the function's header:
              void sll_delete_node(Sllist list, Sllist node_to_delete);