I need to create a decision tree that sorts any three integers in ascending order.
This is what I did:
#include <iostream>
using namespace std;
int main()
{
int x, y, z;
cout << "Enter three integers: ";
cin >> x >> y >> z;
cout << "Your three integers in ascending order are: ";
if(x <= y){
if(x <= z) cout << x << " ";
if(y <= z) cout << y << " " << z << endl;
if(z <= y) cout << z << " " << y << endl;
}
else
if(y <= x){
if(y <= z) cout << y << " ";
if(x <= z) cout << x << " " << z << endl;
if(z <= x) cout << z << " " << x << endl;
}
else
if(z <= x){
if(z <= y) cout << z << " ";
if(y <= x) cout << y << " " << x << endl;
if(x <= y) cout << x << " " << y << endl;
}
}
I don't know what to do to get it to work when the numbers entered are in zyx or zxy order.