Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct tree
- {
- string ime;
- double sr_uspeh;
- tree *left;
- tree *right;
- };
- void CreateP(tree *T, string i, double x)
- {
- if(T != NULL)
- {
- if(x <= T->sr_uspeh)
- {
- if(T->left != NULL)
- {
- CreateP(T->left, i, x);
- }
- else
- {
- tree *z = new tree;
- z->ime = i;
- z->sr_uspeh = x;
- z->left = NULL;
- z->right = NULL;
- T->left = z;
- }
- }
- else
- {
- if(T->right != NULL)
- {
- CreateP(T->right, i, x);
- }
- else
- {
- tree *z = new tree;
- z->ime = i;
- z->sr_uspeh = x;
- z->left = NULL;
- z->right = NULL;
- T->right = z;
- }
- }
- }
- }
- void Print(tree *T)
- {
- if(T == NULL) return;
- Print(T->right);
- cout<<T->ime<<" - "<<T->sr_uspeh<<endl;
- Print(T->left);
- }
- int main()
- {
- int n;
- cout<<"Vuvedi broq uchenici: ";
- cin>>n;
- string ime;
- double sr_uspeh;
- tree *T = new tree;
- cout<<"Ime: ";
- cin>>ime;
- cout<<"Sreden uspeh: ";
- cin>>sr_uspeh;
- T->ime = ime;
- T->sr_uspeh = sr_uspeh;
- T->left = NULL;
- T->right = NULL;
- for(int i = 1; i < n; i++)
- {
- cout<<"Ime: ";
- cin>>ime;
- cout<<"Sreden uspeh: ";
- cin>>sr_uspeh;
- CreateP(T, ime, sr_uspeh);
- }
- Print(T);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement