source: tags/arb_5.2/ARBDBPP/liste.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: 1.4 KB
Line 
1#include <stdio.h>
2#include <arbdb.h>
3#include "arbdb++.hxx"
4
5CLISTENTRY::CLISTENTRY() {
6    entry  = 0;
7    entry2 = 0;
8    next   = 0;
9}
10
11CONTLIST::CONTLIST() {
12    first  = 0;
13    anzahl = 0;
14}
15
16CONTLIST::~CONTLIST() {
17}
18
19
20int CONTLIST::insert(AD_SPECIES *ad_species,AD_ALI *ad_ali)
21{
22    if (element(ad_species,ad_ali)) return 0;
23   
24    CLISTENTRY *newentry;
25    newentry         = new CLISTENTRY;
26    newentry->entry  = ad_species;
27    newentry->entry2 = ad_ali;
28    newentry->next   = first;
29
30    first = newentry;
31    anzahl ++;
32    return 1;
33}
34
35int CONTLIST::element(AD_SPECIES *ad_species,AD_ALI *ad_ali)
36{
37    // testet ob ad_ptr in CONTLIST vorhanden
38    CLISTENTRY *a;
39    if (anzahl == 0) { return 0; }
40    a = first;
41    do {
42        if (a->entry ==ad_species && a->entry2 ==ad_ali) return 1;
43        a = a->next;
44    } while ( a != 0);
45    return 0;       // nicht element der liste
46}
47
48
49
50void CONTLIST::remove(AD_SPECIES *ad_species,AD_ALI *ad_ali)
51{
52    CLISTENTRY* a,*b;
53    if (element(ad_species,ad_ali)) {
54        if (first->entry ==ad_species && first->entry2 ==ad_ali) {
55            first = first->next;
56            delete first;
57        }
58        else {
59            a = first;
60            b = a->next;
61            while (!(b->entry ==ad_species && b->entry2 ==ad_ali)) {
62                a = b;
63                b = b->next;
64            }
65            a->next = b->next;
66            delete b;
67        }
68        anzahl --;
69    }
70}
Note: See TracBrowser for help on using the repository browser.