summaryrefslogtreecommitdiff
path: root/lib/CList.cc
blob: c54e6e1f84e0b8feeb202e1b32054463a013e4d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include "config.h"
#include "CList.h"

CList::CList(CList * IPoint, Datas_t IDatas, Key_t IKey):Left(IPoint), Right(IPoint->Right), Key(IKey), Datas(IDatas)
{
	Left->Right = this;
	if (Right)
		Right->Left = this;
}

CList::CList(void):Left(NULL), Right(NULL), Key(0), Datas(NULL)
{
}
CList::~CList(void)
{
	if (Right)
		delete Right;
}

Datas_t CList::ReadDatas(Cell C)
{
	return ((CList *) C)->Datas;
}

Key_t CList::ReadKey(Cell C)
{
	return ((CList *) C)->Key;
}

Cell CList::Insert(Key_t IKey, Datas_t const &IDatas)
{
	return (new CList(this, IDatas, IKey));
}

Key_t CList::Delete(Datas_t & Datas, Cell C)
{
	Key_t K;

	CList *x = ((CList *) C);

	if (x->Left)
		x->Left->Right = x->Right;
	if (x->Right)
		x->Right->Left = x->Left;
	Datas = x->Datas;
	K = x->Key;
	x->Right = NULL;
	delete x;

	return K;
}

Cell CList::GetFirst(void)
{
	return Right;
}

Key_t CList::Pop(Datas_t & Datas)
{
	return Delete(Datas, GetFirst());
}