Struggling Please Help me with writing this code?


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;


}
first of all sort3 not returning any value
just use void sort3(int vale...)
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....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include<cstdlib>

using namespace std;

int a=0;
int b=0;
int c=0;

void sort3()
{
cout << " Please enter 1st integer : ";
cin >> a;
cout << " Please enter 2nd integer : ";
cin >> b;
cout << " Please enter 3rd integer : ";
cin >> c;

if (a<b) // True
{
   if ((a<b) && (b<c)) // ABC 123
   {
   cout << "Order is A: " << a << ", B: " << b << ", C: " << c << endl;
   }
   else
   if ((a<b) && (a<c) && (b>c)) // ACB 132
   {
   cout << "Order is A: " << a << ", C: " << c << ", B: " << b << endl;
   }
   else // CAB // 231
   {
   cout << "Order is "<< " C: " << c <<", A: " << a << ", B: " << b << endl;
   }
}
else  // False
{
cout << "Write code for A > B " << endl;
}
}

int main()
{
sort3();
return 0;
}
Topic archived. No new replies allowed.