Thx for your fast reply.
is there any difference between
and
?
Can you please explain how a program can be working in debug if it doesn't run outside debug?
anyway, here's all of my code:
main.cpp:
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
#include "intlist.h"
#include "tree.h"
const int TREE_AMOUNT = 100;
void filltree(intlist mylist, bst & mytree, int a)
{
int c = 0;
for(c; c <= NODE_AMOUNT; c++)
{
mytree.addnode(mylist.content[c]);
}
// cout << a << " ";
cout << "Tree created! Internal Path Length: " << mytree.ipl << endl;
}
int main()
{
srand((unsigned)time(0));
int a = 0,c=0;
bst* mytree;
intlist* mylist;
for(a; a<=TREE_AMOUNT; a++)
{
mylist = new intlist;
mytree = new bst;
mylist->fill();
filltree((*mylist), (*mytree), a);
}
cin >> a;
}
intlist.h:
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
const int NODE_AMOUNT = 6;
class intlist{
public:
int content[NODE_AMOUNT];
void disp();
void fill();
void randomize();
private:
};
void intlist::disp()
{
int c = 0;
for(c; c <= NODE_AMOUNT; c++)
{
cout << content[c] << " : ";
}
}
void intlist::fill()
{
int c = 0, r;
bool success;
for(c; c<=NODE_AMOUNT; c++)
{
content[c] = -1;
}
for(c = 0; c<=NODE_AMOUNT; c++)
{
success = false;
while(!success)
{
r = rand()%(NODE_AMOUNT+1);
if(content[r] == -1)
{
content[r] = c;
success = true;
}
}
}
}
tree.h:
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
#include "node.h"
using namespace std;
class bst{
public:
node* root;
node* theplacetobe;
bool empty;
int ipl;
bst::bst();
void addnode(int val);
void print();
void findaspot(int val);
};
bst::bst(){
empty = true;
ipl = 0;
}
void bst::findaspot(int val)
{
node* walker;
if(!empty)
{
bool notthereyet = true;
walker = root;
int depth = 0;
while(notthereyet)
{
depth++;
if(val >= walker->value)
{
// cout << "right" << endl;
if(walker->right == NULL)
{
theplacetobe = walker;
notthereyet = false;
ipl += depth;
}
else
{
walker = walker->right;
}
}
else
{
// cout << "left" << endl;
if(walker->left == NULL)
{
theplacetobe = walker;
notthereyet = false;
ipl += depth;
}
else
{
walker = walker->left;
}
}
}
}
else
{
theplacetobe = root;
}
}
void bst::addnode(int val)
{
findaspot(val);
node* newnode;
if(empty)
{
newnode = root;
newnode = new node;
root = newnode;
empty = false;
}
else
{
if(val >= theplacetobe->value)
{
newnode = theplacetobe->right;
newnode = new node;
theplacetobe->right = newnode;
}
else
{
newnode = theplacetobe->left;
newnode = new node;
theplacetobe->left = newnode;
}
}
newnode->value = val;
}
node.h:
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
class node{
public:
int value;
node* right;
node* left;
node::node();
};
node::node()
{
right = NULL;
left = NULL;
}
Thanks in advance!!
Greetz. Mo