Merge sort an array alphabetically - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Merge sort an array alphabetically

meherdadmeherdad Posts: 7Member
I nned to merge sort and array alphabetically but i cannot figure out how to sort alphabetically.

Can you please help .

If you can just tell me how to sort 2 arrays alphabetically i shall be gratefull

the arrays are

a={ array,stack,queue}

b={boolean,integer,string}

These are 2 arrays that need to be sorted alphabetically .

Please do help

Regards

Comments

  • stephlstephl Posts: 422Member
    : I nned to merge sort and array alphabetically but i cannot figure out how to sort alphabetically.
    :
    : Can you please help .
    :
    : If you can just tell me how to sort 2 arrays alphabetically i shall be gratefull
    :
    : the arrays are
    :
    : a={ array,stack,queue}
    :
    : b={boolean,integer,string}
    :
    : These are 2 arrays that need to be sorted alphabetically .
    :
    : Please do help
    :
    : Regards
    :
    What do your arrays contain exactly? I suppose strings. If yes, this code should

    work.


    [code]#include
    #include
    #include


    #define ARRAYSIZE 4


    int compare(char **ps1,char **ps2)
    {return strcmp(*ps1,*ps2);}


    int main(void)
    {
    char *array[ARRAYSIZE]={"test","work","hello","tests"};
    int i;

    qsort(array,ARRAYSIZE,sizeof (char *),compare);
    for (i=0;i<ARRAYSIZE;i++) printf("%s
    ",array[i]);
    return 0;
    }[/code]

    Take care, Steph.
  • meherdadmeherdad Posts: 7Member
    The code which was provided does not run can you please check and provide me with something .Please I need something soon.

    Thanks


    : I nned to merge sort and array alphabetically but i cannot figure out how to sort alphabetically.
    :
    : Can you please help .
    :
    : If you can just tell me how to sort 2 arrays alphabetically i shall be gratefull
    :
    : the arrays are
    :
    : a={ array,stack,queue}
    :
    : b={boolean,integer,string}
    :
    : These are 2 arrays that need to be sorted alphabetically .
    :
    : Please do help
    :
    : Regards
    :

  • stephlstephl Posts: 422Member
    : The code which was provided does not run can you please check and provide me with something .Please I need something soon.
    :
    : Thanks
    :
    :
    : : I nned to merge sort and array alphabetically but i cannot figure out how to sort alphabetically.
    : :
    : : Can you please help .
    : :
    : : If you can just tell me how to sort 2 arrays alphabetically i shall be gratefull
    : :
    : : the arrays are
    : :
    : : a={ array,stack,queue}
    : :
    : : b={boolean,integer,string}
    : :
    : : These are 2 arrays that need to be sorted alphabetically .
    : :
    : : Please do help
    : :
    : : Regards
    : :
    :
    :
    I compiled the code I gave you successfully with Turbo C 2.01 and it runs and provides the right result. What does not run with you? Are we ok about your goal, that is writing a program that sorts an array of strings alphabetically?

    Take care, Steph.
  • stoberstober Posts: 9,765Member ✭✭✭
    merge sort does NOT merge two arrays into one, if that is what you want to do. Its just another sort algorithm -- qsort() uses quicker sort algorithm, not merge sort.

    If you are instructed to write your own merge-sort algorithm, then here it is:

    http://linux.wku.edu/~lamonml/algor/sort/merge.html

    If you are attempting to merge the two string arrays into one: Create a third array that is large enough to hold all the strings in each of the other two arrays. Copy the strings into the third array, then finally sort this third array using the qsrot() function that stephl posted for you.
Sign In or Register to comment.