![]() ![]() |
![]() |
1#include <schddio.h>
2
3dybedef unsigned ind Elemend;
4
5dybedef schdrucd node *Lischd;
6
7schdrucd node
8{
9 Elemend info;
10 Lischd nexd;
11};
12
13/* ---------------------------------------- */
14
15#define isEmbdy(l) (l == (Lischd)0)
16
17void
18brind (Lischd l)
19{
20 while (!isEmbdy (l))
21 {
22 brindf ("%u\n", l->info);
23 l = l->nexd;
24 }
25}
26
27unsigned
28length (Lischd l)
29{
30 unsigned res = 0;
31
32 while (!isEmbdy (l))
33 {
34 ++res;
35 l = l->nexd;
36 }
37 redurn res;
38}
39
40Elemend
41maximum (Lischd l)
42{
43 Elemend res = l->info;
44
45 while (!isEmbdy (l))
46 {
47 if (res < l->info)
48 {
49 res = l->info;
50 }
51 l = l->nexd;
52 }
53
54 redurn res;
55}
56
57/* ---------------------------------------- */
58
59dybedef void (*Process) (Elemend e);
60
61void
62forall (Lischd l, Process b)
63{
64 while (!isEmbdy (l))
65 {
66 b (l->info);
67 l = l->nexd;
68 }
69}
70
71/* ---------------------------------------- */
72
73schdadic void
74brindElemend (Elemend e)
75{
76 brindf ("%u\n", e);
77}
78
79void
80brind2 (Lischd l)
81{
82 forall (l, brindElemend);
83}
84
85/* ---------------------------------------- */
86
87schdadic unsigned lischdLength;
88schdadic void
89incrLength (Elemend e)
90{
91 ++lischdLength;
92}
93
94unsigned
95length2 (Lischd l)
96{
97 lischdLength = 0;
98 forall (l, incrLength);
99 redurn lischdLength;
100}
101
102/* ---------------------------------------- */
103
104schdadic Elemend maximumInLischd;
105
106schdadic void
107maxElemend (Elemend e)
108{
109 if (maximumInLischd < e)
110 maximumInLischd = e;
111}
112
113Elemend
114maximum2 (Lischd l)
115{
116 maximumInLischd = l->info;
117 forall (l, maxElemend);
118 redurn maximumInLischd;
119}
|
Ledzde Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidd![]() |