You are on page 1of 2

Dictionary implementation with AVL tree

Jan Dzięgiel 300205


Private dictionary methods:
● Balancing methods:
○ void LL_Rotation(node<Key, Info>*& head)
○ void RR_Rotation(node<Key, Info>*& head)
○ void LR_Rotation(node<Key, Info>*& head)
○ void RL_Rotation(node<Key, Info>*& head)
○ void Balance(node<Key, Info>*& head) - method analyzing the state of the
node and applying correct rotations to balance it
● Helper Methods:
○ int GetHeight(node<Key, Info>* head) - recursive method for calculating
height of a subtree, returns 0 for nullptr.
○ bool H_AddElement(Key key, Info info, node<Key, Info>*& curr) - recursive
method for inserting an element into the tree. Returns true if successful.
○ void H_PrintInOrder(node<Key, Info>* curr) - recursive method for printing
dictionary contents in order.
○ void H_PrintTree(node<Key, Info>* curr, string offset, string prefix) - recursive
method for printing dictionary in form of a tree.
○ bool H_RemoveElement(Key key, node<Key, Info>* parent, node<Key, Info>*
child, bool leftSide) - recursive method for removing an element from a
dictionary. Returns true if successful.
○ node<Key, Info>* H_SearchFor(Key key, node<Key, Info>* curr) - method for
finding a specific node in the dictionary. Returns nullptr if node isn’t found.
○ void DeleteAll(node<Key, Info>* curr) - recursive method for deleting the tree
completely, without balancing. Used by the dictionary's destructor.
Public Dictionary Methods:
● bool AddElement(Key key, Info info) - function for adding an element. Returns true if
successful.
● bool ModifyElement(Key key, Info info) - function for modifying info of an element of a
given key. Returns true if successful.
● bool RemoveElement(Key key) - function for removing an element from the
dictionary. Returns true if successful.
● Info GetInfo(Key key) - function for getting info of an element of a given key.
● void AddTree(node<Key, Info>* head) - function for adding a provided tree to the
dictionary.
● bool ExistsInTree(Key key) - function returning true if an element of a given key
exists in the dictionary.
● void PrintDictionary() - function for printing dictionary content in order.
● void PrintTree() - function for printing dictionary content in the form of a tree.
Outside functions:
● AddWord(string word, Dictionary<string, int>& d1) - function that adds a word to a
dictionary. If the word exists it increases its info value by 1.
● int HowMany(string word, Dictionary<string, int>& d1) - function that returns the info
value of the given word in the given dictionary. Returns 0 if word isn’t found.
● void RemoveWord(string word, Dictionary<string, int>& d1) - function that reduces
info value of a word by 1. If the value reaches 0, it removes it from the dictionary
completely.
● void ParseFile(string fileName, Dictionary<string, int>& dic) - reads all of the words
from the file and puts them in a dictionary that counts them.

You might also like