Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("bst.in");
- ofstream fout("bst.out");
- struct nod
- {
- int info, fr;
- nod*st,*dr;
- }*v;
- int n,k;
- void Inserare(nod*&c, int k)
- {
- if(c)
- if(c->info==k) c->fr++;
- else if(c->info<k) Inserare(c->dr,k);
- else Inserare(c->st,k);
- else
- {
- c=new nod;
- c->info=k;
- c->fr=1;
- c->st=c->dr=0;
- }
- }
- void inordine(nod*c)
- {
- if(c)
- {
- inordine(c->st);
- for(int i=1;i<=c->fr;i++) fout<<c->info<<' ';
- inordine(c->dr);
- }
- }
- int main()
- {
- fin>>n;
- for(int i=1;i<=n;i++)
- {
- fin>>k;
- Inserare(v,k);
- }
- inordine(v);
- return 0;
- }
RAW Paste Data