pc_math
چهارشنبه 17 بهمن 1386, 11:17 صبح
این برنامه وقتی اجرا میشه درست عمل نمی کنه:ناراحت: وقتی کامپایل می کنه ایرادی نمی گیره
#include <iostream.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define TRUE 1
void input();
int menu_select();
void maketree(struct tree *);
void find(struct tree *);
void inorder(struct tree *s);
struct tree{
struct tree *left;
char word[20];
char mean[20];
struct tree *right;
};
struct tree *start, *node;
char pword[20];
int main(){
start = NULL;
while(TRUE){
switch(menu_select()){
case 1:
input();
break;
case 2:
gotoxy(20,14);
cout<<"Enter word for search:";
cin.get(pword, 20);
find(start);
getch();
break;
case 3:
clrscr();
cout<<"\n travers tree in inorder\n";
gotoxy(6,4);
cout<<" word mean";
gotoxy(6,5);
cout<<"----------- ----------";
inorder(start);
cout<<"\n press a key to continue ....";
getch();
break;
case 4:
exit(0);
}//end of switch
}// end of while
}// end of main
//*************
void input(){
int i;
char wstr[10];
clrscr();
gotoxy(4, 3);
cout<<" word mean \n";
gotoxy(4, 4);cout<<"----------- ----------";
i = 5;
while(TRUE){
node = (struct tree *) malloc(sizeof(struct tree));
node -> left = NULL;
node -> right = NULL;
gotoxy(4, i);
cin.get(node -> word,20);
if(!node -> word[0]){
gotoxy(5, i + 2);
cout<<"\n press a key to continue ....";
getch();
break;
}
gotoxy(23, i);
cin.get(wstr, 10);
node -> mean = wstr;
if(start == NULL)
start = node;
else
maketree(start);
i++;
}// end of while
}
//************
int menu_select(){
int choice;
char s[5];
clrscr();
gotoxy(20,4);
cout<<" 1- enter word in tree.";
gotoxy(20,6);
cout<<"2- search for word in tree.";
gotoxy(20,8);
cout<<"3- print information on screen. ";
gotoxy(20,10);
cout<<"4-quit from program.";
do{
gotoxy(20,12);
cout<<"Enter your select(1-4):";
cin.get(s, 5);
choice = atoi(s);
} while(choice < 0 || choice > 4);
return choice;
}
//*****************
void maketree(struct tree *top){
struct tree *help;
help = top;
while(help != NULL){
if(node -> mean>help->mean){
if(help-> right != NULL)
help = help -> right;
else{
help -> right = node;
break;
}//end of else
}//end of if
else{
if(help-> left != NULL)
help = help -> left;
else{
help -> left = node;
break;
}//end of else
}//end of else
}//end of while
}
//******************
void find (struct tree *s){
if(s == NULL)
return;
find(s -> left);
if(strcmp(s -> word, pword) == 0){
cout<<"\n "<<pword<<" has maen:";
cout<<s -> mean;
return ;
}
find(s -> right);
}
//**********************
void inorder (struct tree *s){
if( s == NULL)
return;
inorder(s -> left);
cout<<"\n"<<s -> word;
cout<<"\t\t\t"<<s -> mean;
inorder(s -> right);
}
#include <iostream.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define TRUE 1
void input();
int menu_select();
void maketree(struct tree *);
void find(struct tree *);
void inorder(struct tree *s);
struct tree{
struct tree *left;
char word[20];
char mean[20];
struct tree *right;
};
struct tree *start, *node;
char pword[20];
int main(){
start = NULL;
while(TRUE){
switch(menu_select()){
case 1:
input();
break;
case 2:
gotoxy(20,14);
cout<<"Enter word for search:";
cin.get(pword, 20);
find(start);
getch();
break;
case 3:
clrscr();
cout<<"\n travers tree in inorder\n";
gotoxy(6,4);
cout<<" word mean";
gotoxy(6,5);
cout<<"----------- ----------";
inorder(start);
cout<<"\n press a key to continue ....";
getch();
break;
case 4:
exit(0);
}//end of switch
}// end of while
}// end of main
//*************
void input(){
int i;
char wstr[10];
clrscr();
gotoxy(4, 3);
cout<<" word mean \n";
gotoxy(4, 4);cout<<"----------- ----------";
i = 5;
while(TRUE){
node = (struct tree *) malloc(sizeof(struct tree));
node -> left = NULL;
node -> right = NULL;
gotoxy(4, i);
cin.get(node -> word,20);
if(!node -> word[0]){
gotoxy(5, i + 2);
cout<<"\n press a key to continue ....";
getch();
break;
}
gotoxy(23, i);
cin.get(wstr, 10);
node -> mean = wstr;
if(start == NULL)
start = node;
else
maketree(start);
i++;
}// end of while
}
//************
int menu_select(){
int choice;
char s[5];
clrscr();
gotoxy(20,4);
cout<<" 1- enter word in tree.";
gotoxy(20,6);
cout<<"2- search for word in tree.";
gotoxy(20,8);
cout<<"3- print information on screen. ";
gotoxy(20,10);
cout<<"4-quit from program.";
do{
gotoxy(20,12);
cout<<"Enter your select(1-4):";
cin.get(s, 5);
choice = atoi(s);
} while(choice < 0 || choice > 4);
return choice;
}
//*****************
void maketree(struct tree *top){
struct tree *help;
help = top;
while(help != NULL){
if(node -> mean>help->mean){
if(help-> right != NULL)
help = help -> right;
else{
help -> right = node;
break;
}//end of else
}//end of if
else{
if(help-> left != NULL)
help = help -> left;
else{
help -> left = node;
break;
}//end of else
}//end of else
}//end of while
}
//******************
void find (struct tree *s){
if(s == NULL)
return;
find(s -> left);
if(strcmp(s -> word, pword) == 0){
cout<<"\n "<<pword<<" has maen:";
cout<<s -> mean;
return ;
}
find(s -> right);
}
//**********************
void inorder (struct tree *s){
if( s == NULL)
return;
inorder(s -> left);
cout<<"\n"<<s -> word;
cout<<"\t\t\t"<<s -> mean;
inorder(s -> right);
}