CAN ANYONE TELL ME Y MY BUBBLE SORT WONT WORK

# include <iostream>
# include <ctime>
# include <cmath>
# include <iomanip>
# include <fstream>
# include <cstdlib>
using namespace std;
void readmatrix(int [5][4]);
void printmatrix(int [5][4]);
void sortlow(int[5][4]);
void sorthigh(int [5][4]);

int main()
{
int infile;
ifstream input ("ARRAY.DAT");
//ofstream output ("ARRAYSORT1.OUT");

int array1[5][4];

readmatrix (array1);
printmatrix (array1);
cout<<endl<<endl;

sorthigh(array1);
printmatrix(array1);
cout<<endl<<endl;

sortlow(array1);
printmatrix(array1);

system("pause");
}

void readmatrix(int x[5][4])
{
int rows,columns,input;

for (rows=0;rows<5;rows++)
for (columns=0;columns<4;columns++)
input>>x[rows][columns];
}
void printmatrix(int y[5][4])
{
int rows,columns;

for (rows=0;rows<5;rows++)
{
for (columns=0;columns<4;columns++)
cout<<y[rows][columns]<<" "<<endl;
}
}
void sorthigh(int sort[5][4])
{
int high,m,i,a,n,row;
int end=5;
int temp1[4],temp2[4];

for (m=end-1;m>=0;m--)
{
high = sort[m][0];
for (i=m;i>=0;i--)
{
if (high >= sort[i][0])
{
high = sort[i][0];
row =i;
}
for (a=0;a<4;a++)
{
temp1[a] = sort[m][a];
temp2[a] = sort[row][a];
sort[m][a] = temp2[a];
sort[row][a] = temp1[a];
}
}
}
}
void sortlow(int sort[5][4])
{
int low,m,i,a,n,row;
int end=5;
int temp1[4],temp2[4];

for (m=end-1;m>=0;m--)
{
low = sort[m][0];
for (i=m;i>=0;i--)
{
if (low <= sort[i][0])
{
low = sort[i][0];
row =i;
}
for (a=0;a<4;a++)
{
temp1[a] = sort[m][a];
temp2[a] = sort[row][a];
sort[m][a] = temp2[a];
sort[row][a] = temp1[a];
}
}
}
}

ARRAY.DAT

3 33 333 3333
5 55 555 5555
1 11 111 1111
4 44 444 4444
2 22 222 2222
How do you know it's not your input or output that's faulty? What have you done to debug it? Please make your question more detailed, and format your code so that we can read it.
Last edited on
closed account (z05DSL3A)
How To Ask Questions The Smart Way
http://www.cplusplus.com/forum/articles/1295/

How to put code into your postings
http://www.cplusplus.com/forum/articles/1624/
Topic archived. No new replies allowed.