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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
#include<string.h>
#include<fstream>
#include<iomanip>
#include<stdio.h>
using namespace std;
class employee_record{
private:
string emp_id;
string emp_name;
string emp_add;
int emp_salary;
string emp_pos;
string emp_email;
public:
string key(){
return emp_id;
}
friend class binary;
friend ostream& operator<<(ostream& os, const employee_record& s){
os << s.emp_id << '\n';
os << s.emp_name<< '\n';
os << s.emp_add<< '\n';
os << s.emp_salary<< '\n';
os << s.emp_pos<< '\n';
os << s.emp_email<< '\n';
return os;
}
friend istream& operator>>(istream& is, employee_record& s){
is >> s.emp_id ;
is >> s.emp_name;
is >> s.emp_add ;
is >> s.emp_salary ;
is >> s.emp_pos;
is >> s.emp_email ;
return is;
}
void insertdata(){
cout <<"enter employee's id ";
cin >>emp_id;
cout <<"enter employee's name ";
cin >>emp_name;
cout <<"enter employee's address ";
cin >>emp_add;
cout <<"enter employee's salary ";
cin >>emp_salary;
cout <<"enter employee's position ";
cin >>emp_pos;
cout <<"enter employee's email ";
cin >>emp_email;
}
};
class binary{
private:
struct tree_node
{
tree_node* left;
tree_node* right;
int data;
employee_record edata;
};
tree_node* root;
public:
binary()
{
root=NULL;
}
bool isEmpty() const { return root==NULL; }
void print_inorder();
void inorder(tree_node*);
void print_preorder();
void preorder(tree_node*);
void print_postorder();
void postorder(tree_node*);
void insert(employee_record x);
void remove(int);
void search(int key);
int getheight() const;
int getcount() const;
void showstruct() const;
};
// Smaller elements go left
// larger elements go right
void binary::insert(employee_record x)
{
tree_node* t = new tree_node;
tree_node* parent;
t->edata = x;
t->left = NULL;
t->right = NULL;
parent = NULL;
if(isEmpty()) root = t;
else
{ // x.insertdata();
//Note: ALL insertions are as leaf nodes
tree_node* curr;
curr = root;
// Find the Node's parent
while(curr)
{
parent = curr;
if(t->edata.getid() > curr->edata.getid()) curr = curr->right;
else curr = curr->left;
}
if(t->edata.getid() < parent->edata.getid())
parent->left = t;
else
parent->right = t;
}
}
//file.close();
void filltree(binary *b)
{
employee_record edata;
//ofstream record("Dict.txt",ios::app);
//record << edata;
//record.close();
string empid;
string name, add, pos,email;
int salary;
ifstream file;
file.open("Dict.txt");
cout<<"opening\n";
if(!file){
cout<<"Error Opening File\n ";
}
while(file >> empid>>name>>add>>salary>>pos>>email)
{
edata.setid(empid);
edata.setname(name);
edata.setadd(add);
edata.setsalary(salary);
edata.setpos(pos);
edata.setemail(email);
cout<<"yye\n";
cout<<edata.getid()<< "\n"<<edata.getname()<< "\n"<<edata.getadd()<<"\n"<<edata.getsalary()<<"\n"<<edata.getpos()<<"\n"<<edata.getemail()<<endl;
cout<<"ffworking\n";
//edata.insertdata();
(*b).insert(edata);
//file.seekg(0, ios::beg);
}
file.close();
}
int main()
{
binary b;
avltree avl;
employee_record er;
employee_record er1;
filltree(&b);
b.print_preorder();
int salary;
string name, add, pos, email;
string id;
int ch,ch1,ch2,tmp,tmp1,tmp2,item;
cout<<"**********************************************************\n";
cout<<"* EMPLOYEE RECORD * \n";
cout<<"***********************************************************\n";
cout<<"1. Binary Search Tree\n2. AVL Tree\n";
cout<<"Enter your choice\n";
cin>>ch1;
if(1){
cout<<" Binary Search Tree Operations "<<endl;
cout<<" ----------------------------- "<<endl;
cout<<" 1. Insertion/Creation "<<endl;
cout<<" 2. In-Order Traversal "<<endl;
cout<<" 3. Pre-Order Traversal "<<endl;
cout<<" 4. Post-Order Traversal "<<endl;
cout<<" 5. Removal "<<endl;
cout<<" 6. Search "<<endl;
cout<<" 7. Exit "<<endl;
cout<<" Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1 :
cout<<"Enter Employee Id\n :";
cin>>id;
cout<<"Enter Employee Name\n :";
cin>>name;
cout<<"Enter Employee Address\n :";
cin>>add;
cout<<"Enter Employee salary\n :";
cin>>salary;
cout<<"Enter Employee position\n :";
cin>>pos;
cout<<"Enter Employee email\n :";
cin>>email;
er.setid(id);
er.setname(name);
er.setadd(add);
er.setsalary(salary);
er.setpos(pos);
er.setemail(email);
cout<<"2\n"; filltree(&b);
b.insert(er);
cout<<"why\n";
break;
case 2 : cout<<endl;
cout<<" In-Order Traversal "<<endl;
cout<<" -------------------"<<endl;
b.print_inorder();
break;
case 3 : cout<<endl;
cout<<" Pre-Order Traversal "<<endl;
cout<<" -------------------"<<endl;
b.print_preorder();
break;
case 4 : cout<<endl;
cout<<" Post-Order Traversal "<<endl;
cout<<" --------------------"<<endl;
b.print_postorder();
break;
case 5 : cout<<" Enter data to be deleted : ";
cin>>tmp1;
b.remove(tmp1);
break;
case 6 : cout<<" Enter data to be searched :";
cin>>tmp2;
break;
case 7 :
return 0;
break;
default:cout<<"\nInvalid choice....\n";
}}
|