hw5 - hw5.cpp Defines the entry point for the console

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// hw5.cpp : Defines the entry point for the console application. // / #include "stdafx.h" # #include <iostream> #include <cstdlib> #include <iomanip> #include <cmath> # #define M 7 // M = 1 + (block_size-block_ptr)/(key_size + block_ptr) //#define M 15 typedef int dtype; // the key #define BLC_SIZE 512 # enum status {Insert_not_complete, Success, Duplicate_key, Underflow, Not_found}; struct Dat_blc { char dat[BLC_SIZE]; // Data }; } using namespace std; u template <class T> class node { public: node (T value); node (T value, node * left, node * right); ~node<T>(){}; // public data area for value field T value; node * left() const; void left(node * l); node * right() const; void right(node * r); // data areas node * leftptr; node * rightptr; }; template <class T> node<T> *node<T>::left() const{return this->leftptr;} template <class T> void node<T>::left(node * l){this->leftptr = l;} template <class T> node<T> *node<T>::right() const{return this->rightptr;} template <class T> void node<T>::right(node * r){this->rightptr = r;} template <class T> node<T>::node(T value){this->value = value; leftptr = NULL; rightptr = NULL;} r template <class T> class searchTree{ public: searchTree():root(NULL){counter = 0;}; searchTree(searchTree<T> &){counter = 0;} virtual ~searchTree<T>(){}; // protocol for search trees virtual void add(T value); void increment(){ counter ++;} // increment counter of the iterations unsigned long int retCount(){return counter;} void print() { cout << counter << "\n"; } protected:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// data areas node<T> *root; unsigned long int counter; }; } template <class T> void searchTree<T>::add(T val) { if (root) { node<T> * current = root; node<T> * child; while (current) { this->increment(); //counter incrementation if (current->value < val) { child = current->right(); if (!child) { current->right(new node<T>(val)); return; } } else { child = current->left(); if (!child) { current->left(new node<T>(val)); return; } } current = child; } } else root = new node<T>(val); this->increment();} //counter incrementation i template <class T> class avlNode : public node<T> { public: avlNode(T value); avlNode(T, node<T> *, node<T> *); ~avlNode<T>(){} void left(avlNode * v); avlNode * left() const; void right(avlNode * v); avlNode * right() const; avlNode * add(T value, unsigned long int &count); private: short balFac; // balance factor, either -1, 0 or 1 avlNode * singleRotateLeft(unsigned long int &count); avlNode * singleRotateRight(unsigned long int &count); avlNode * balance(unsigned long int &count); //T value; avlNode * leftptr; avlNode * rightptr; }; } template <class T> avlNode<T> *avlNode<T>::left() const{return this->leftptr;}; template <class T> void avlNode<T>::left(avlNode * v){this->leftptr = v;}; template <class T> avlNode<T> *avlNode<T>::right() const{return this->rightptr;}; template <class T> void avlNode<T>::right(avlNode * v){this->rightptr = v;}; template <class T> avlNode<T>::avlNode(T value): node<T>::node(value){leftptr = NULL; rightptr = NULL; balFac = 0;}
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/24/2010 for the course COS 221 taught by Professor Christozov during the Spring '10 term at American University in Bulgaria.

Page1 / 8

hw5 - hw5.cpp Defines the entry point for the console

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online