Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct tree{
- int num;
- struct tree* sad;
- struct tree* sae;
- }Tree;
- Tree* createTree(){
- return NULL;
- }
- int treeisEmpty (Tree* t){
- return t == NULL;
- }
- void insertTree(Tree** t, int num){
- if(*t == NULL){
- *t = (Tree*)malloc(sizeof(Tree));
- (*t)->sae = NULL;
- (*t)->sad = NULL;
- (*t)->num = num;
- }else {
- if(num < (*t) ->num){
- insertTree(&(*t)->sae, num);
- }
- if(num > (*t) ->num) {
- insertTree(&(*t) ->sad,num);
- }
- }
- }
- void showTreePre (Tree* t){
- printf("\n<");
- if(!treeisEmpty(t)){
- printf("%d", t->num);
- showTreePre(t->sae);
- showTreePre(t->sad);
- }
- printf(">");
- }
- int main(){
- Tree* t = createTree();
- insertTree(&t, 8);
- insertTree(&t, 7);
- insertTree(&t, 6);
- if(treeisEmpty(t)){
- printf("\n Arvore Vazia!!!!!\n");
- }else{
- printf("\n Arvore NAO vazia!!!!!! ");
- }
- showTreePre(t);
- free(t);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement