sometime it sort correctly and sometimes dont, i do not know what is wrong with my codes pls help. thnks
#include<iostream>
using namespace std;
#include<iomanip>
using std::setw;
int main( )
{
const int arraySize=2;
const int test = 4;
int data[arraySize][test ] = {{13,10,1,19},{8,6,5,9}};
int data1[1][4];
int insert;
cout<<"\nUnsorted Array:\n";
for(int i =0; i< arraySize; i++)
{
for(int j=0; j< test; j++)
{
cout<<setw(4)<< data[i][j];
}
cout<<endl;
}
for(int next=0; next < arraySize; next++)
{
for(int i =1; i< test; i++)
{
insert = data[next][i];
int k = i;
while((k>0)&&(data[next][k-1] > insert))
{
data[next][i]=data[next][k-1];
k--;
}
data[next][k]=insert;
}
}
cout<<"\nSorted Array"<<endl;
for(int i =0; i< arraySize; i++)
{
for(int j=0; j< test; j++)
{
cout<<setw(4)<< data[i][j];
}
cout<<endl;
}
getchar();
}
result for example
unsorted Array
13 10 1 19
8 6 5 9
Sorted Array
1 13 10 19
5 8 6 9