School Commit Init
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
//DO NOT INCLUDE SORTEDBAGITERATOR
|
||||
|
||||
//DO NOT CHANGE THIS PART
|
||||
typedef int TComp;
|
||||
typedef TComp TElem;
|
||||
typedef bool(*Relation)(TComp, TComp);
|
||||
#define NULL_TCOMP -11111;
|
||||
|
||||
class BSTNode {
|
||||
public:
|
||||
TComp elem;
|
||||
BSTNode* left;
|
||||
BSTNode* right;
|
||||
BSTNode* parent;
|
||||
~BSTNode() {
|
||||
delete left;
|
||||
delete right;
|
||||
}
|
||||
int count;
|
||||
};
|
||||
|
||||
class SortedBagIterator;
|
||||
|
||||
class SortedBag {
|
||||
friend class SortedBagIterator;
|
||||
|
||||
private:
|
||||
//TODO - Representation
|
||||
BSTNode* root;
|
||||
Relation relation;
|
||||
int length;
|
||||
int reccuriveCount(BSTNode* node, int frequency) const;
|
||||
|
||||
public:
|
||||
//constructor
|
||||
SortedBag(Relation r);
|
||||
|
||||
//adds an element to the sorted bag
|
||||
void add(TComp e);
|
||||
|
||||
//removes one occurence of an element from a sorted bag
|
||||
//returns true if an element was removed, false otherwise (if e was not part of the sorted bag)
|
||||
bool remove(TComp e);
|
||||
|
||||
//checks if an element appearch is the sorted bag
|
||||
bool search(TComp e) const;
|
||||
|
||||
//returns the number of occurrences for an element in the sorted bag
|
||||
int nrOccurrences(TComp e) const;
|
||||
|
||||
//returns the number of elements from the sorted bag
|
||||
int size() const;
|
||||
|
||||
//returns an iterator for this sorted bag
|
||||
SortedBagIterator iterator() const;
|
||||
|
||||
//checks if the sorted bag is empty
|
||||
bool isEmpty() const;
|
||||
|
||||
//destructor
|
||||
~SortedBag();
|
||||
|
||||
int elementsWithThisFrequency(int frequency) const;
|
||||
};
|
||||
Reference in New Issue
Block a user