-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortedIndexedList.h
62 lines (47 loc) · 1.27 KB
/
SortedIndexedList.h
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
#pragma once
class ListIterator;
typedef int TComp;
typedef bool (*Relation)(TComp, TComp);
#define NULL_TCOMP -11111
struct DLLNode{
TComp info;
int next;
int prev;
~DLLNode() {};
};
class SortedIndexedList {
private:
friend class ListIterator;
private:
DLLNode* elements;
int cap;
int nrElems;
int head;
int tail;
int firstEmpty;
Relation rel;
public:
// constructor
SortedIndexedList(Relation r);
// returns the size of the list
int size() const;
//checks if the list is empty
bool isEmpty() const;
// returns an element from a position
//throws exception if the position is not valid
TComp getElement(int pos) const;
// adds an element to a given position
//throws an exception if the position is not valid
void add(TComp e);
// removes an element from a given position
//returns the removed element
//throws an exception if the position is not valid
TComp remove(int pos);
// searches for an element and returns the first position where the element appears or -1 if the element is not in the list
int search(TComp e) const;
// returns an iterator set to the first element of the list or invalid if the list is empty
ListIterator iterator();
void remove_by_step(int k);
//destructor
~SortedIndexedList();
};