Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

METROPOLIA

Information Technology

Lab. exercise 12
TI00AC30 Algorithms and Datastructures

Page 1
03.04.2014 JV

Exercise 12a. (Function pointers)


Do only one of the following exercises.

Option 1.
Create a program, which has an array of times (using your old ADT Time). First enter
times to that array from the keyboard (using your readTime() function) in a random order.
Then order those time entries in a standard way (later time is bigger, e.g. 11:03 is bigger
than 10:54), and print that ordered list of times.
After that (in the same program) order then those times in an array by the minutes field
only (e.g. 10:54 is bigger than 11:03) and print out the same array of times.
Note: use the standard qsort() function for the sorting operation.

Option 2.
Implement an iterator for_all for your linked list implementation (exercises 9 and 10). The
iterator should have a function pointer as a parameter. First create a list of arbitrary length.
Then use the iterator to read new characters to every node. Print then again the whole list
(using iterator) to see that the reading operation has been successfully implemented
Note: in this case we assume that the list already exist.

Exercise 12b. (List of lists, bonus exercise, 0,25p)


At the lectures we were studying the problem of sparse matrix implemented as linked list
structure where the matrix is represented by the linked list whose nodes contain the linked
list representing a row whose nodes contain the cell information of the matrix. If the
linked list is implemented in universal way, then these two linked list structures can be
implemented with a single linked list implementation.
In this exercise we implement a matrix of characters. One row in this matrix can represent
a string, and therefore the whole matrix represent then list of strings. It is then possible to
store e.g. names to the linked list representing rows. Then this matrix represents list of
names.
Use the list.lib library (and of course include the interface list.h) from the exercise 9b as
your implementation of a general list. Notice that you cannot make any modifications to
the list implementation because it is used via library. You can implement all the needed
datatypes (e.g. Tstringlist and Tcharlist) and operation functions (initialize_string_list,
initialize_char_list, insert_to_string_list, insert_to_char_list and print_string_list) using
list.lib container library with small cover or adaptor functions.
Use the following main program as a tester for your matrix implementation.

METROPOLIA
Information Technology

void main (){


TstringList
int i;

Lab. exercise 12
TI00AC30 Algorithms and Datastructures

stringList;

TcharList charList;

initialize_string_list(&stringList);
initialize_char_list(&charList);
for (i = 0; i < 4 ; i++) //adds characters a,b,c ja d
insert_to_char_list(&charList, 'a'+ i);
insert_to_string_list(&stringList, charList);
initialize_char_list(&charList);
for (i = 0; i < 4 ; i++) //adds characters e,f,g,h
insert_to_char_list(&charList, 'e'+ i);
insert_to_string_list(&stringList, charList);
initialize_char_list(&charList);
for (i = 0; i < 4 ; i++) //adds characters i, j ,k l
insert_to_char_list(&charList, 'i'+ i);
insert_to_string_list(&stringList, charList);
print_string_list(stringList);
}

fflush(stdin); getchar();

Page 2
03.04.2014 JV

You might also like