Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- struct nod
- {
- char info[50];
- nod *st, *dr;
- };
- void add_nod(nod *&rad, char a[])
- {
- if(rad == NULL)
- {
- nod *r = new nod;
- strcpy(r->info, a);
- r->st = r->dr = NULL;
- rad = r;
- return;
- }
- else
- {
- if(strcmp(a, rad->info) > 0)
- add_nod(rad->st, a);
- else
- {if(strcmp(a, rad->info) < 0)
- add_nod(rad->dr, a);
- else
- return;
- }
- }
- }
- void inordine(nod *rad)
- {
- if(rad)
- {
- inordine(rad->st);
- printf("%s, ", rad->info);
- inordine(rad->dr);
- }
- }
- void cit_cuvinte(nod *rad)
- {
- char a[50];
- int n, i = 0;
- printf("n: " );
- scanf("%d", &n);
- while(i < n)
- {
- scanf("%s", a);
- add_nod(rad, a);
- ++i;
- }
- inordine(rad);
- }
- int main()
- {
- nod *rad = NULL;
- cit_cuvinte(rad);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement