html>C-ohjelmointi, laskuharj. 1

C-programming Autumn 1999

Problems for Exercise 6 (25.-29.10.1999)

Write your C-programs from the very beginning with a computer. Points will be given only for solutions proven by a computer. Make sure of the correct functioning by compiling your program, correcting possible errors and by running program, if necessary using different test inputs.

NB! NB! NB! NB!

These exercises will not be dealt with during exercise sessions, but the solution should be sent by e-mail to your own exercise instructor on Friday, October 29 at 10.00 at the latest.The model solutions will be posted on the course pages on Monday, October 31 at the latest.

1. Write the function struct list *around(struct lista*1), which turns a simplex linked list around, so that the final node becomes the first one, the second last becomes the second and so on. Letters have been saved in the elements. Write a main program, too, with which you can test the function.
You will find other processing functions for a simplex linked list among the lecture material. 2. Write structures struct list and struct node that can be used for the processing of a in rising order ordered duplex linked list. The elements of the list are integers, and the list keeps an account of the number of elements in the list. Write also function for creating an empty list and the function add_node, which adds a node to the list:

 
     int add_node(struct list *l, struct node *s);
        /* adds a node to the list in its correct place so that 
           the elements of the list are still in a rising order*/
Write a main program, too, with which you can test the functions.

3. For the processing of the ordered list in the previous exercise, write the following functions:

    struct node *find_node(struct list *l, int i);
         /* finds a node in the list, in which the integer i 
            has been saved, and returns the pointer to the node 
            that was found. If the element looked for is not found
            in the list, the output is NULL*/

    int  remove_node(struct list *l, struct node *s);
        */removes a node from the list and frees the space of that node*/

    int number_of_elements (struct list *l):
        /* returns the number of elements in the list*/
Write a main program with which to test the functions.

4. Plan adequate structures for the complex numbers. Write the functions using these structures for the addition and multiplication of complex numbers, and for outputting complex numbers. A complex number consists of a real part and an imaginary part; x=a +bi. Numbers are added by terms in the addition function and i*i=-1 in multiplication. The values a and b are real numbers.

5. Write a program in which the arguments given on a command line are a group of file names, and the output is the number of lines in each file, grouped according to file. If a file specified does not exist, the program outputs an error message at the name of this file, but keeps on outputting the number of lines in other files.

6. Fill in and return the course evaluation from the Department's Web pages. The address is http://www.cs.helsinki.fi/kurssit/kyselyt/syksy_1999/