Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Tree
- {
- int num;
- Tree* Left;
- Tree* Right;
- Tree(int x) : num(x), Left(NULL), Right(NULL) { }
- };
- int add(Tree* &t, int num)
- {
- if (!t)
- {
- t = new Tree(num);
- return 1;
- }
- if (t->num == num) return 0;
- if (t->num > num) return add(t->Left, num);
- return add(t->Right, num);
- }
- int main()
- {
- Tree* tr = NULL;
- int ans = 0;
- int n;
- cin >> n;
- while (n)
- {
- ans += add(tr, n);
- cin >> n;
- }
- cout << ans << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment