Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- struct treenode {
- int info;
- treenode* esq;
- treenode* dir;
- };
- typedef treenode* treenodeptr;
- void tInsere(treenodeptr &p, int x)
- {
- if (p == NULL) // insere na raiz
- {
- p = new treenode;
- p->info = x;
- p->esq = NULL;
- p->dir = NULL;
- }
- else if (x < p->info) // insere na subarvore esquerda
- tInsere(p->esq,x);
- else // insere na subarvore direita
- tInsere(p->dir,x);
- }
- int main()
- {
- int N;
- treenodeptr tree = NULL;
- cin >> N;
- for(int i = 0; i < N; i++)
- {
- int x, highest, lowest;
- cin >> x;
- highest = x;
- lowest = x;
- while(x != -1)
- {
- tInsere(tree, x);
- if(x > highest)
- highest = x;
- else if(x < lowest)
- lowest = x;
- cin >> x;
- }
- cout << lowest << " " << highest << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement