source: tags/arb_5.2/MULTI_PROBE/MP_list.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1#include <stdio.h>
2
3#include <MultiProbe.hxx>
4
5void 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
34void 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
64void 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
103short 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
117MP_list::MP_list()
118{
119    this->first = NULL;
120    this->last  = NULL;
121    this->no_of_entries = 0;
122}
123
124
125MP_list::~MP_list()
126{
127}
128
Note: See TracBrowser for help on using the repository browser.