My Project
DSA.h
Go to the documentation of this file.
1 
9 #include <bits/stdc++.h>
10 
12 #define ll long long int
13 
15 #define vi vector<int>
16 
18 #define vll vector<ll>
19 using namespace std;
20 
21 /* ------------------------------- Data Structures ---------------------------------- */
22 
23 // ------------------------------- Singly Linked List -----------------------------
24 
30 
31  public:
32 
35 
38 
43 
49 
50 };
51 
58 ostream& operator<<(ostream &out, const SinglyLinkedListNode &node);
59 
65 
66  public:
67 
70 
73 
78 
83  void insert(ll data);
84 
90  SinglyLinkedListNode* find(ll data);
91 
97  bool deleteVal(ll data);
98 
103  void printer(string sep);
104 
108  void reverse();
109 
110 };
111 
119 
120 // ------------------------------- Doubly Linked List -----------------------------
121 
127 
128  public:
129 
132 
135 
138 
143 
149 
150 };
151 
158 ostream& operator<<(ostream &out, const DoublyLinkedListNode &node);
159 
165 
166  public:
167 
170 
173 
178 
183  void insert(ll data);
184 
189  void printer(string sep);
190 
194  void reverse();
195 
196 };
197 
198 // ------------------------------- Binary Search Tree -----------------------------
199 
203 class BSTNode {
204 
205  public:
206 
209 
212 
215 
218 
223  BSTNode (ll val);
224 
225 };
226 
233 ostream& operator<<(ostream &out, const BSTNode &node);
234 
240 
241  public:
242 
245 
247  enum order {PRE, IN, POST};
248 
253 
258  void insert(ll val);
259 
265  void traverse(BSTNode* T, order tt);
266 
272  ll height(BSTNode *T);
273 
274 };
275 
276 // ------------------------------- Suffix Trie -----------------------------
277 
282 class Trie {
283 
284  public:
285 
288 
290  map<char,Trie*> nodes;
291 
295  Trie();
296 
303  bool find(Trie* T, char c);
304 
309  void insert(string s);
310 
316  bool checkPrefix(string s);
317 
323  ll countPrefix(string s);
324 
325 };
326 
327 // ------------------------------- Heap -----------------------------
328 
334 void swap(int &x, int &y);
335 
336 class Heap {
342  int* H;
343  int maxSize;
344  int n;
345 
346  public:
347 
352  Heap(int capacity);
353 
359  int parent(int i);
360 
366  int left(int i);
367 
373  int right(int i);
374 
379  void insert(int e);
380 
385  int min();
386 
391  void Heapify(int root);
392 
396  void deleteMin();
397 
398 };
BSTNode::left
BSTNode * left
pointer to the left child
Definition: DSA.h:214
DoublyLinkedListNode::next
DoublyLinkedListNode * next
pointer to the next node
Definition: DSA.h:134
DoublyLinkedList::head
DoublyLinkedListNode * head
pointer to the head
Definition: DSA.h:169
SinglyLinkedListNode
Singly Linked List Node class. Available member functions include default constructor and initialisin...
Definition: DSA.h:29
DoublyLinkedListNode::data
ll data
data stored in the node
Definition: DSA.h:131
Trie
Trie class. Available member functions include default constructor, find, insert, checkPrefix and cou...
Definition: DSA.h:282
DoublyLinkedListNode::prev
DoublyLinkedListNode * prev
pointer to the previous node
Definition: DSA.h:137
BSTNode::right
BSTNode * right
pointer to the right child
Definition: DSA.h:217
operator<<
ostream & operator<<(ostream &out, const SinglyLinkedListNode &node)
Function to print a Singly Linked List Node.
Definition: DSA.cpp:17
BSTNode
BST Node class. Available member functions include initialising constructor.
Definition: DSA.h:203
Trie::nodes
map< char, Trie * > nodes
map/dictionary of nodes
Definition: DSA.h:290
BinarySearchTree::order
order
types of traversals
Definition: DSA.h:247
SinglyLinkedList::head
SinglyLinkedListNode * head
pointer to the head
Definition: DSA.h:69
SinglyLinkedList::tail
SinglyLinkedListNode * tail
pointer to the tail
Definition: DSA.h:72
SinglyLinkedList
Singly Linked List class. Available member functions include default constructor, insert,...
Definition: DSA.h:64
Heap
Definition: DSA.h:336
merge
SinglyLinkedList merge(SinglyLinkedList list1, SinglyLinkedList list2)
Merge two sorted linked lists.
Definition: DSA.cpp:84
BSTNode::info
ll info
info stored in the node
Definition: DSA.h:208
SinglyLinkedListNode::data
ll data
data stored in the node
Definition: DSA.h:34
DoublyLinkedList::tail
DoublyLinkedListNode * tail
pointer to the tail
Definition: DSA.h:172
DoublyLinkedList
Doubly Linked List class. Available member functions include default constructor, insert,...
Definition: DSA.h:164
swap
void swap(int &x, int &y)
Swap function.
Definition: DSA.cpp:331
ll
#define ll
long long int macro
Definition: DSA.h:12
BinarySearchTree
BinarySearchTree class. Available member functions include default constructor, insert,...
Definition: DSA.h:239
DoublyLinkedListNode
Doubly Linked List Node class. Available member functions include default constructor and initialisin...
Definition: DSA.h:126
BSTNode::level
ll level
level of the node
Definition: DSA.h:211
Trie::count
ll count
count of the string from root to leaf
Definition: DSA.h:287
SinglyLinkedListNode::next
SinglyLinkedListNode * next
pointer to the next node
Definition: DSA.h:37
BinarySearchTree::root
BSTNode * root
pointer to the root
Definition: DSA.h:244