i have two text files which contain integer type data i want to perform bubble sort on them.

#include <iostream>
using namespace std;
#include <fstream>
#include <string>
int main(){
const int require=15;
const int require2=100000 ;
int count;
int count2;
int swap,temp,i,j;
int data[require];
int data2[require2];
int numofvalues;
ifstream getdata, getdat;
getdata.open("Input.txt");
getdat.open("list.txt");
count=0;
// geting data from 1st fille
while (!getdata.eof())
{
getdata>>data[count];
count ++;

}
//geting data from 2nd file
count2=0;

while (!getdat.eof())
{
getdat>>data2[count2];
count2++;

}


//sorting code of 1st file

for (i=1; i <16; i++)

{
swap=0;
for (j=0; j<15; j++)
{
if(data[j]>data[j+1])
{
temp= data[j];
data[j]= data[j+1];
data[j+1]= temp;
swap =1;
}


}

if (swap==0){
break;
}
}
//sorting code of 2nd file

for (i=1; i <100001; i++)

{
swap=0;
for (j=0; j<100000; j++)
{
if(data2[j]>data2[j+1])
{
temp= data2[j];
data2[j]= data2[j+1];
data2[j+1]= temp;
swap =1;
}


}

if (swap==0){
break;
}
}


// storing the data into new file
ofstream storedata;
storedata.open("outputfile.txt");
for (i=1; i <16; i++)

{
storedata<<data[i]<<endl;
data[i]++;


}
// storig the econd file data
for (i=1; i <100001=; i++)

{
storedata<<data2[i]<<endl;
data2[i]++;


}
getdata.close();

getdat.close();


system ("pause");
return 0;


}
Last edited on
You should edit your post to add code tags so that your code retains indentation. Just put the following "tags" around your code:

[code]
your code here
[/code]

It looks like you should divide your program into functions, one for reading data into an array, one for sorting an array, and one for printing an array.

What exactly is the problem you are having?
Last edited on
Topic archived. No new replies allowed.