Hello.

I have a two structure arrays that are sorted. ı wanted to put these arrays into third array as a sorted. and then ı wanted to put these values into the file. into my array one and array two , there is no same number so ı thought something to puth them into third array.

However , with respect to my method, into structure array3 nothing write.

struct record array1[10];
struct record array2[10];
struct record array3[20];
.
.
.
.


int e=0,f=0,g=0;

while ( e!=10 || f!=10);
{
if(array1[e].ave<array2[f].ave)
{
array3[g]=array1[e];
e=e+1;
g=g+1;
}
else if ( array2[f].ave<array1[e].ave)
{
array3[g]=array2[f];
f=f+1;
g=g+1;
}
}





if(f==10)
{
for(int k=e; k<10;++k)
{
array3[g]=array1[k];
g=g+1;
}
}
else if ( e==10)
{
     for (int j=f; j<10 ; ++j)
     {
     array3[g]=array2[j];
     g=g+1;
     }
}

Sounds like you need`to do the "merge" part of a merge sort. Time to stick some debugging code in there. Lines 16 -21 added by me. Make sure the while loop functions as you think it should...

while ( e!=10 || f!=10);
{
if(array1[e].ave<array2[f].ave)
{
array3[g]=array1[e];
e=e+1;
g=g+1;
}
else if ( array2[f].ave<array1[e].ave)
{
array3[g]=array2[f];
f=f+1;
g=g+1;
}

    cout << "g = " << g << ": sorted array so far : ";
    for(int i = 0; i < g; i++)
    {
        cout << array3[i] << " ";
    }
    cout << "\n";
}

Note. If you format your code, your error(s) will be easier to spot.

yes ı could not solve this problem. I tried to send message today ı do not know whether or not it reached you.

This article has been dead for over six months. Start a new discussion instead.