1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include<iostream>
using namespace std ;
#include "Hfile.h"
base::base()
{
root = NULL ;
balance = 0 ;
}
int base::add_leaf_ini()
{
cout<<"name please \n ";
char name[100];
cin.get( name , 100 ) ;
cin.ignore( 100, '\n' );
cout<<"type please \n ";
char type[100];
cin.get( type , 100 ) ;
cin.ignore( 100, '\n' );
cout<<"cost please \n ";
int cost ;
cin>>cost ;
cin.ignore ( 100 ) ;
//comfirm loop
cout<<"Test";
balance = cost + balance ;
base::add_leaf( root , name , cost , type );
return 1;
}
int base::add_leaf( tree *& root , char * name , int temp_cost , char * type )
{
if(!root)
{
root = new tree ;
root -> head = new node ;
root -> head -> add_no_chain ( name , type );
root -> head -> set_next_to_null( );
root -> cost = temp_cost ;
root -> left = root -> right = NULL;
}
else
{
if ( temp_cost == root -> cost )
{
root -> head -> add_chain( name , type );
}
else
{
if( root->cost > temp_cost )
{
add_leaf( root -> right , name , temp_cost , type );
}
else
{
add_leaf( root -> left , name , temp_cost , type ) ;
}
}
}
return 1;
}
int base::display()
{
root -> head -> display();
return 1;
}
base::~base()
{
delete root ;
root = NULL ;
}
|