1 | #include <stdio.h> |
---|
2 | |
---|
3 | #include <MultiProbe.hxx> |
---|
4 | |
---|
5 | void MP_list::append_elem_backwards( void *elem ) |
---|
6 | { |
---|
7 | MP_list_elem *new_list_elem; |
---|
8 | |
---|
9 | if ( elem == NULL ) |
---|
10 | return; |
---|
11 | |
---|
12 | new_list_elem = new MP_list_elem; |
---|
13 | |
---|
14 | new_list_elem->elem = elem; |
---|
15 | new_list_elem->next = NULL; |
---|
16 | |
---|
17 | if ( this->first == NULL) |
---|
18 | { |
---|
19 | this->first = new_list_elem; |
---|
20 | this->last = new_list_elem; |
---|
21 | this->no_of_entries++; |
---|
22 | |
---|
23 | return; |
---|
24 | } |
---|
25 | |
---|
26 | new_list_elem->next = this->first; |
---|
27 | this->first = new_list_elem; |
---|
28 | this->no_of_entries++; |
---|
29 | |
---|
30 | return; |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | void MP_list::append_elem( void *elem ) |
---|
35 | { |
---|
36 | MP_list_elem *new_list_elem; |
---|
37 | |
---|
38 | if ( elem == NULL ) |
---|
39 | return; |
---|
40 | |
---|
41 | new_list_elem = new MP_list_elem; |
---|
42 | |
---|
43 | new_list_elem->elem = elem; |
---|
44 | new_list_elem->next = NULL; |
---|
45 | |
---|
46 | if ( this->first == NULL) |
---|
47 | { |
---|
48 | this->first = new_list_elem; |
---|
49 | this->last = new_list_elem; |
---|
50 | this->no_of_entries++; |
---|
51 | |
---|
52 | return; |
---|
53 | } |
---|
54 | |
---|
55 | this->last->next = new_list_elem; |
---|
56 | this->last = new_list_elem; |
---|
57 | this->no_of_entries++; |
---|
58 | |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | void MP_list::delete_elem( void *elem ) |
---|
65 | { |
---|
66 | MP_list_elem *current_list_elem, |
---|
67 | *previous_list_elem; |
---|
68 | |
---|
69 | current_list_elem = this->first; |
---|
70 | previous_list_elem = NULL; |
---|
71 | |
---|
72 | while ( (current_list_elem!= NULL) && (current_list_elem->elem != elem) ) |
---|
73 | { |
---|
74 | previous_list_elem = current_list_elem; |
---|
75 | current_list_elem = current_list_elem->next; |
---|
76 | } |
---|
77 | |
---|
78 | if ( current_list_elem == NULL ) |
---|
79 | return; |
---|
80 | |
---|
81 | if ( current_list_elem == this->first ) |
---|
82 | { |
---|
83 | if ( current_list_elem == this->last ) |
---|
84 | this->last = NULL; |
---|
85 | |
---|
86 | this->first = current_list_elem->next; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | previous_list_elem->next = current_list_elem->next; |
---|
91 | |
---|
92 | if ( current_list_elem == this->last ) |
---|
93 | this->last = previous_list_elem; |
---|
94 | } |
---|
95 | |
---|
96 | this->no_of_entries--; |
---|
97 | delete current_list_elem; |
---|
98 | return; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | short MP_list::is_elem( void *elem ) |
---|
104 | { |
---|
105 | MP_list_elem *current_list_elem = this->first; |
---|
106 | |
---|
107 | if ( elem == NULL ) |
---|
108 | return ( FALSE ); |
---|
109 | |
---|
110 | while (current_list_elem && current_list_elem->elem != elem) |
---|
111 | current_list_elem = current_list_elem->next; |
---|
112 | |
---|
113 | return (current_list_elem) ? TRUE : FALSE; |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | MP_list::MP_list() |
---|
118 | { |
---|
119 | this->first = NULL; |
---|
120 | this->last = NULL; |
---|
121 | this->no_of_entries = 0; |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | MP_list::~MP_list() |
---|
126 | { |
---|
127 | } |
---|
128 | |
---|