Please could someone help me? my merge sort code is not sorting properly. this is the code:

#include <iostream>
#include <string>
using namespace std;
void mergeArray(int a[],int sizeA, int b[],int sizeB,int result[],int *size);
void display (int c[],int num);

int  main ()

{
        int a[]={45, 88, 12, 23, 65 };
        int b[]={10, 15 , 98, 59};
        int result [100];
        int size;
        mergeArray(a,5,b,4,result,&size);
        display(result,size);
}



void mergeArray(int a[],int sizeA, int b[],int sizeB,int result[],int *size)
{
        for (int i=0; i<sizeA;i++)
                result [i]=a[i];

                        for (int i=0;i<sizeB;i++)
                                result[sizeA+i]=b[i];
                        *size=sizeA+sizeB;


}



void display (int c[],int num)
{
        for (int i=0; i<num;i++)
                cout<<c[i]<<"  ";

}

Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

other than your main function not having a return 0;
There isn't an obvious error on your merge function

You have not got any reference to a sort function in your code though.

ok thank you. i am new at this, how can i exatly sort this code?? i know im close but im still searching. could you help?

First you have to show that you know what you want to achieve with your code. This might require pencil and paper.

The next step is to try and write a function that sorts the data this will be some kind of iteration and you need to work out what each step needs to show.

There are lots of techniques for sorting well but for now you just need to show that you can think through how to the problem. So show your first effort of what you think the function should look like. There are important concepts to learn by doing this task so it is important that you can think through the problem yourself.

ok thank you. i am new at this, how can i exatly sort this code?? i know im close but im still searching. could you help?

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