Foros del Web » Programación para mayores de 30 ;) » C/C++ »

problema con arbol binario

Estas en el tema de problema con arbol binario en el foro de C/C++ en Foros del Web. me da 2 errores 21 `main' must return `int' Build Error] ["arbol binario.o"] Error 1 ayuda no se q hacerle @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código C++: Ver ...
  #1 (permalink)  
Antiguo 07/06/2012, 12:47
Avatar de W_NEMESIS  
Fecha de Ingreso: mayo-2012
Ubicación: pasto
Mensajes: 25
Antigüedad: 11 años, 11 meses
Puntos: 1
Exclamación problema con arbol binario

me da 2 errores

21 `main' must return `int'
Build Error] ["arbol binario.o"] Error 1

ayuda no se q hacerle

Código C++:
Ver original
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. struct node
  6.     {
  7.     int data;
  8.     node *left;
  9.     node *right;
  10.     };
  11.  
  12. node *tree=NULL;
  13. node *insert(node *tree,int ele);
  14.  
  15. void preorder(node *tree);
  16. void inorder(node *tree);
  17. void postorder(node *tree);
  18. int count=1;
  19.  
  20. void main()
  21.     {
  22.     system("cls");
  23.     int ch,ele;
  24.     do
  25.         {
  26.         system("cls");
  27.         cout<<"\n\t\a\a1----INSERT A NODE IN A BINARY TREE.\a\a";
  28.         cout<<"\n\t\a\a2----PRE-ORDER TRAVERSAL.\a\a";
  29.         cout<<"\n\t\a\a3----IN-ORDER TRAVERSAL.\a\a";
  30.         cout<<"\n\t\a\a4----POST-ORDER TRAVERSAL.\a\a";
  31.         cout<<"\n\t\a\a5----EXIT.\a\a";
  32.         cout<<"\n\t\a\aENTER CHOICE::\a\a";
  33.         cin>>ch;
  34.         switch(ch)
  35.             {
  36.             case 1:
  37.             cout<<"\n\t\a\aENTER THE ELEMENT::\a\a";
  38.             cin>>ele;
  39.             tree=insert(tree,ele);
  40.             break;
  41.              
  42.             case 2:
  43.             cout<<"\n\t\a\a****PRE-ORDER TRAVERSAL OF A TREE****\a\a";
  44.             preorder(tree);
  45.             break;
  46.            
  47.             case 3:
  48.             cout<<"\n\t\a\a****IN-ORDER TRAVERSAL OF A TREE****\a\a";
  49.             inorder(tree);
  50.             break;
  51.            
  52.             case 4:
  53.             cout<<"\n\t\a\a****POST-ORDER TRAVERSAL OF A TREE****\a\a";
  54.             postorder(tree);
  55.             break;
  56.            
  57.             case 5:
  58.             exit(0);
  59.             }
  60.         }while(ch!=5);
  61.     }
  62.  
  63. node *insert(node *tree,int ele)
  64. {
  65.     if(tree==NULL)
  66.         {
  67.         tree=new node;
  68.         tree->left=tree->right=NULL;
  69.         tree->data=ele;
  70.         count++;
  71.         }
  72.     else
  73.     if(count%2==0)
  74.     tree->left=insert(tree->left,ele);
  75.     else
  76.     tree->right=insert(tree->right,ele);
  77.     return(tree);
  78. }
  79.  
  80. void preorder(node *tree)
  81. {
  82.     if(tree!=NULL)
  83.     {
  84.         cout<<tree->data;
  85.         preorder(tree->left);
  86.         preorder(tree->right);
  87.         getch();
  88.     }
  89. }
  90.    
  91. void inorder(node *tree)
  92. {
  93.     if(tree!=NULL)
  94.     {
  95.         inorder(tree->left);
  96.         cout<<tree->data;
  97.         inorder(tree->right);
  98.         getch();
  99.     }
  100. }
  101.  
  102. void postorder(node *tree)
  103. {
  104.     if(tree!=NULL)
  105.     {
  106.         postorder(tree->left);
  107.         postorder(tree->right);
  108.         cout<<tree->data;
  109.         getch();
  110.     }
  111. }
  #2 (permalink)  
Antiguo 07/06/2012, 13:46
 
Fecha de Ingreso: abril-2010
Ubicación: Rosario
Mensajes: 1.850
Antigüedad: 14 años
Puntos: 228
Respuesta: problema con arbol binario

Tenes algunos errores muy pavos.. Fiajte que cuando definis un struct para definir una variabler de ese tipo tenes que poner la palabra strcut, a menos que uses un typedef como lo defini yo.... Fijate que adentro del struct si defini dos punteros de ese tipo y use el nombre largo.

Lo demas son boludeces. Saludos

Código C++:
Ver original
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. typedef struct Tnode
  6. {
  7.     int data;
  8.     struct Tnode *left;
  9.     struct Tnode *right;
  10.    
  11. } node;
  12.  
  13. node *tree=NULL;
  14. node *insert(node *tree,int ele);
  15.  
  16. void preorder(node *tree);
  17. void inorder(node *tree);
  18. void postorder(node *tree);
  19. int count=1;
  20.  
  21. #include <iostream>
  22.  
  23. using namespace std;
  24.  
  25.  
  26.  
  27. int main()
  28.     {
  29.     system("cls");
  30.     int ch,ele;
  31.     do
  32.         {
  33.         system("cls");
  34.         cout<<"\n\t\a\a1----INSERT A NODE IN A BINARY TREE.\a\a";
  35.         cout<<"\n\t\a\a2----PRE-ORDER TRAVERSAL.\a\a";
  36.         cout<<"\n\t\a\a3----IN-ORDER TRAVERSAL.\a\a";
  37.         cout<<"\n\t\a\a4----POST-ORDER TRAVERSAL.\a\a";
  38.         cout<<"\n\t\a\a5----EXIT.\a\a";
  39.         cout<<"\n\t\a\aENTER CHOICE::\a\a";
  40.         cin>>ch;
  41.         switch(ch)
  42.             {
  43.             case 1:
  44.             cout<<"\n\t\a\aENTER THE ELEMENT::\a\a";
  45.             cin>>ele;
  46.             tree=insert(tree,ele);
  47.             break;
  48.              
  49.             case 2:
  50.             cout<<"\n\t\a\a****PRE-ORDER TRAVERSAL OF A TREE****\a\a";
  51.             preorder(tree);
  52.             break;
  53.            
  54.             case 3:
  55.             cout<<"\n\t\a\a****IN-ORDER TRAVERSAL OF A TREE****\a\a";
  56.             inorder(tree);
  57.             break;
  58.            
  59.             case 4:
  60.             cout<<"\n\t\a\a****POST-ORDER TRAVERSAL OF A TREE****\a\a";
  61.             postorder(tree);
  62.             break;
  63.            
  64.             case 5:
  65.             exit(0);
  66.             }
  67.         }while(ch!=5);
  68.         return 0;
  69.     }
  70.  
  71. node *insert(node *tree,int ele)
  72. {
  73.     if(tree==NULL)
  74.         {
  75.         tree=new node;
  76.         tree->left=tree->right=NULL;
  77.         tree->data=ele;
  78.         count++;
  79.         }
  80.     else
  81.     if(count%2==0)
  82.     tree->left=insert(tree->left,ele);
  83.     else
  84.     tree->right=insert(tree->right,ele);
  85.     return(tree);
  86. }
  87.  
  88. void preorder(node *tree)
  89. {
  90.     if(tree!=NULL)
  91.     {
  92.         cout<<tree->data;
  93.         preorder(tree->left);
  94.         preorder(tree->right);
  95.         getch();
  96.     }
  97. }
  98.    
  99. void inorder(node *tree)
  100. {
  101.     if(tree!=NULL)
  102.     {
  103.         inorder(tree->left);
  104.         cout<<tree->data;
  105.         inorder(tree->right);
  106.         getch();
  107.     }
  108. }
  109.  
  110. void postorder(node *tree)
  111. {
  112.     if(tree!=NULL)
  113.     {
  114.         postorder(tree->left);
  115.         postorder(tree->right);
  116.         cout<<tree->data;
  117.         getch();
  118.     }
  119. }

Etiquetas: binario, arboles
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:25.