This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DO.h
76 lines (53 loc) · 1.85 KB
/
DO.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#pragma once
typedef int TCheie;
typedef int TValoare;
#define NULL_TVALOARE -1
#include <utility>
typedef std::pair<TCheie, TValoare> TElem;
class Iterator;
typedef bool(*Relatie)(TCheie, TCheie);
class DO {
friend class Iterator;
private:
int cap;
TElem* elems;
int* left;
int* right;
int* parent;
int root;
int first_free;
int create_node(TElem e);
int add_rec(int upper, int p, TElem e, int& old_value);
TValoare find_rec(int p, int key) const;
int del_rec(int p, TCheie c, TValoare& res);
int size = 0;
Relatie r;
int next_ord(int p) const;
int min(int p) const;
int max(int p) const;
public:
void print();
void print_rec(int p, int lvl);
// constructorul implicit al dictionarului
DO(Relatie r);
// adauga o pereche (cheie, valoare) in dictionar
//daca exista deja cheia in dictionar, inlocuieste valoarea asociata cheii si returneaza vechea valoare
// daca nu exista cheia, adauga perechea si returneaza null: NULL_TVALOARE
TValoare adauga(TCheie c, TValoare v);
//cauta o cheie si returneaza valoarea asociata (daca dictionarul contine cheia) sau null: NULL_TVALOARE
TValoare cauta(TCheie c) const;
//sterge o cheie si returneaza valoarea asociata (daca exista) sau null: NULL_TVALOARE
TValoare sterge(TCheie c);
//returneaza numarul de perechi (cheie, valoare) din dictionar
int dim() const;
//verifica daca dictionarul e vid
bool vid() const;
// se returneaza iterator pe dictionar
// iteratorul va returna perechile in ordine dupa relatia de ordine (pe cheie)
Iterator iterator() const;
// destructorul dictionarului
~DO();
// returnează diferența dintre valoarea maximă și valoarea minimă (presupunem valori întregi)
// Dacă dicționarul este vid, se returnează -1
int diferentaValoareMaxMin() const;
};