Thanks
#include<iostream>
using namespace std;
int main()
{
int rows = 10;
int array[rows][3];
int i,x;
cout<< "The Random unsorted numbers are: "<<endl;
for(i=0; i<13; i++)
{
x=(rand() % ((40-15) +1) + 15);
array[i][0]=0;
array[i][1]=0;
array[i][2]=0;
array[0][0]=3;
//array[1][0]=-32767; //low
//array[2][0]= 32767; //high
array[1][0]=10;
array[2][0]=99;
array[2][1]=1;
array[1][2]=2;
array[i][0]=x;
cout<<array[i][0]<< " ";
}
cout<<endl<<endl;
cout<<"Value Before After"<<endl;
for(i=0; i<13; i++)
{
cout<<" "<<array[i][0]<<" "<< array[i][1]<< " " << array[i][2] <<endl;
}
cout<<endl;
for(i=3; i<=10; i++)
{
if(array[i][0]>=array[1][0])
{
// follow the link, change array[][] (the look at)
// moves on yes, changes on no
int before, after;
if(i==3)
{
after= array[1][2];
before= array[2][1];
}
else
{
before = array[i][1];
after = array[i][2];
}
if(array[i][0]>= array[1][array[i][2]]) // goes to the after column to check the next number
{
cout<<"The value ("<<array[i][0]<<") is greater than low (" <<array[1][0]<<") go to [0]["<<after<<"]"<<endl;
cout<<"check if " <<array[i][0]<<" is < [0][" << array[array[i][2]][0]<<"]"<<endl;
cout<<"before = "<<before<<endl;
cout<<"after = " << after<< endl<<endl;
if(array[i][0] <= array[after][0]) // check if less then after if no then changes
{
cout<<"The value is less then 'high' value."<<endl;
cout<<"array[0][0] = "<<array[0][0]<<endl;
cout<<"before = "<< before<<endl;
cout<<"after = "<<after<<endl<<endl;
array[i][2]=after; // changes the 'after' col
array[i][1]=before; //changes the 'before' col
}
array[array[i][2]][array[i][1]] = array[0][0];
array[array[i][1]][array[i][2]] = array[0][0];
++array[0][0];
}
}
}
cout<< "Value Before After" <<endl;
for(i=0; i<13; i++)
{
cout<<" "<<array[i][0]<<" "<< array[i][1]<< " " << array[i][2] <<endl;
}
cout<<endl;
system("Pause");
return 0;
}

Ask A New Question
Reply





MultiQuote




|