| dagreat45 (12) | |
|
Struggling with this C++ program please I need some help Write a C++ Function void sort3(void) which prompts the user to enter three integers, a,b,c and outputs their values in ascending order according to the following decision tree(click the link) http://img809.imageshack.us/img809/9589/28769489.png I neeed another way to write this code #include<iostream> #include<cstdlib> using namespace std; int a=0; int b =0; int c =0; typedef struct node { int* val1; int* val2; struct node* left; struct node* right; int isleaf; int* ptrs[3]; }node; //tree consturtcion node node1 = {NULL,NULL,NULL,NULL,1, {&a,&b,&c } }; node node2 = {NULL,NULL,NULL,NULL,1, {&a,&c,&b } }; node node3 = {NULL,NULL,NULL,NULL,1, {&c,&a,&b } }; node node4 = {NULL,NULL,NULL,NULL,1, {&b,&c,&a } }; node node5 = {NULL,NULL,NULL,NULL,1, {&c,&b,&a } }; node node6 = {&a,&c,&node2,&node3,0, NULL }; node node7 = {NULL,NULL,NULL,NULL,1, {&b,&a,&c } }; node node8 = {&b,&c,&node4,&node5,0, NULL }; node node9 = {&b,&c,&node1,&node6,0, NULL }; node node10 = {&a,&c,&node7,&node8,0, NULL }; node node11 = {&a,&b,&node9,&node10,0, NULL }; void rsort( node* ptr ) { if(ptr->isleaf ==1){ int i=0; int value; cout<<"printing the sorting order\n"; while(i < 3) { value = *(ptr->ptrs[i]); cout<<value; i++; } return; } if ( *(ptr->val1) < *(ptr->val2) ){ return rsort(ptr->left); } else{ return rsort(ptr->right); } } int sort3(int vala,int valb, int valc) { a = vala; b = valb; c = valc; rsort(&node11); } int main() { sort3(5,5,1); return 0; } | |
|
|
|
| codeback99 (6) | |
|
first of all sort3 not returning any value just use void sort3(int vale...) | |
|
|
|
| SamuelAdams (185) | |||
|
He basically gave you the code when he gave you the Image file. All you have to do is read his instructions, which it seems you didn't follow at all. I'm not sure what void sort3(void) means, you might want to check on that.I know there is more than one way to write it, but he's not asking for all the stuff you did.... It's not finished....
| |||
|
|
|||