# Series 9. ADT â SR Approach (visit 1)

```sp | PAI | Department of Informatics | Faculty of Science | University of Fribourg | Switzerland
Series 9. ADT – SR Approach (visit 1)
nd
System-oriented Programming, BSc Course, 2 Sem., Prof. B. Hirsbrunner, A. Halabi and Ch. Göttel
Handout on Tue, 21 April 2015
Due on Mo, 27 April, 12:00
Reading. Study the lecture notes and the tutorial 'ADT Object' (p. 1 - 4) very carefully, in conjunction with
the source codes of ADT_Obj/STACK_Light/SR available at http://diuf.unifr.ch/pai/sp > Labs > adt >
ADT_Obj.zip.
You should spend at least 2 hours for this reading. Note that you already studied, in a simplified version,
all these source codes in Series 4 to 7. You will find them again in ADT_Obj/STACK_Light/SR_Basic.
Please note down any questions and comments you have and put them on the course forum or bring
them to class.
All exercises of this Series are done in the spirit of the SR approach.
1. traverse() – sum of all keys
Extend STACK_Light/SR/STACK_Test.c with a function void sum(buf_t *buf) allowing to
calculate the sum of the keys of the elements stored in the stack object. Implement and test it.
Hint: a good understanding of buf_t, defined in STACK_Light/MTE/type_f.h, is necessary. If you are
lost, study the already available functions: display(buf_t *), occurrence(buf_t *),
size(buf_t *).
2. traverse() – what ever your imagination inspires you
Propose another function f for 'stack_traverse(f,&buf)'. Then implement and test it.
3. Token List: data structure and pointer manipulation
In graph theory, a token list is a list where the access, manipulator and traverse operations are done
ahead or behind a token. Graphically it is represented as in Fig. 3.1. In computer science, a token list is
usually implemented with a doubly linked list, supplied with a token, cf. Fig. 3.2. A text editor is a classical
example of a token list, where the token is the cursor !
a. Define a data type tl_node_t and token_t describing this token doubly linked list, where each
tl_node contains also an element of type elt_t.
b. Implement the following functions in the spirit of the SR approach:
1. void tlist_move_token_backward()
2. void tlist_put_elt_behind_token(elt_t *e)
A test on machine is out of scope of this Series of exercises. But your code should be compilable with
'gcc –c'.
Figure 3.1. Graphical representation of a token list with resp. 0 and 4 vertices
succ
pred
token
behind
token
ahead
Figure 3.2. A possible data structure for the token lists of Fig. 3.1
```