Assignment # 3: Source Code
Assignment # 3: Source Code
ASSIGNMENT # 3
SOURCE CODE:
#include <iostream>
#include <fstream>
#include<conio.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#include <bits/stdc++.h>
#define C 10
// The handle class stores and manages a pointer to the base //class. The type of the object to which that pointer
points will //vary; it can point at either a base- or a derived-type object. //Users access the operations of the
inheritance hierarchy //through the handle.
HANDLE hStdOut;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD count;
DWORD cellCount;
COORD homeCoords = { 0, 0 };
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if (!FillConsoleOutputCharacter(
hStdOut,
(TCHAR)' ',
cellCount,
homeCoords,
&count
)) return;
/* Fill the entire buffer with the current colors and attributes */
if (!FillConsoleOutputAttribute(
hStdOut,
csbi.wAttributes,
cellCount,
homeCoords,
&count
)) return;
SetConsoleCursorPosition(hStdOut, homeCoords);
//-----------------------------------------------------------
struct node{
string data;
int height;
};
int max(int n1, int n2){//function to get max of two numbers
return n1;
return n2;
if(root == NULL){
return;
s += C;
printTree(root->right,s);
cout<<root->data<<"->"<<endl;
printTree(root->left, s);
cout<<"<<"<<i<<">>"<<endl;
printTree(root,0);
string s1 = bitset<8>(name[0]).to_string();
s1 = s1.substr(s1.length() - 3);
int n = 0;
int s = s1.size();
if(s1[i] == '1'){
n += pow(2.0, i);
n += pow(0.0, i);
return n;
//-----------------------------------------------------------------------------
//-------------------------------------------------------------------------------
class AvlTree{
public:
AvlTree(){
this->root = NULL;
leftNode->right = currentNode;
currentNode->left = rightNode;
currentNode->height = max(getHeight(currentNode->left),getHeight(currentNode-
>right)) + 1;
leftNode->height = max(getHeight(leftNode->left),getHeight(leftNode->right)) + 1;
return leftNode;
rightNode->left = currentNode;
currentNode->right = leftNode;
currentNode->height = max(getHeight(currentNode->left),getHeight(currentNode-
>right)) + 1;
leftNode->height = max(getHeight(rightNode->left),getHeight(rightNode->right)) + 1;
return rightNode;
while(temp->left != NULL){
temp = temp->left;
}
return temp;
return currentNode->right->height + 1;
return currentNode->left->height + 1;
return currentNode->right->height + 1;
}return 0;
if(currentNode == NULL){
return 0;
return currentNode->height;
if(currentNode == NULL){
return 0;
return balance;
}
node *insertNode(node *root, string data){
if(root == NULL){
currentNode->data = data;
root = currentNode;
root->height = 1;
return root;
}else{
root->left = insertNode(root->left,data);
}else{
return root;
root->height = calculateHeight(root);
return rotateRight(root);
root->left = rotateLeft(root->left);
return rotateRight(root);
}
if(balance > 1 && data > root->left->data){
root->left = rotateLeft(root->left);
return rotateRight(root);
root->right = rotateRight(root->right);
return rotateLeft(root);
return root;
if(root == NULL){
return root;
}else{
node *temp;
if(root->left){
temp = root->left;
}else{
temp = root->right;
}
temp = root;
root == NULL;
}else{
*root = *temp;
free(temp);
}else{
root->data = temp->data;
if(root == NULL){
return root;
return rotateRight(root);
root->left = rotateLeft(root->left);
return rotateRight(root);
return rotateLeft(root);
root->right = rotateRight(root->right);
return rotateLeft(root);
return root;
};
//-----------------------------------------------------------------
class HashTable{
int size;
AvlTree *tree;
public:
return getIndex(name);
HashTable(int size){
this->size = size;
}
void insertItem(string data){
int i = hasher(data);
return tree[i].root->height;
deleteItem(string data){
int i = hasher(data);
int i = hasher(data);
void displayHash(){
output(tree[i].root, i);
};
int main(int argc, char** argv) {
string arr[91];
string data;
int i;
if(file.is_open()){
//get each line from the text file and store in the variable l
c++;//increment c
if(file.eof()) break;
HashTable hash(8);
hash.insertItem(arr[j]);
}
int choice = 0;//user choice
string choice2;
clearScreen();
cout<<"4. Exit"<<endl;
cin>>choice;
switch(choice){
case 1:
getline(cin, data);
getline(cin, data);
hash.insertItem(data);
cin>>choice2;
break;
case 2:
getline(cin, data);
getline(cin, data);
hash.deleteItem(data);
break;
case 3:
hash.displayHash();
cin>>choice2;
break;