jeudi 29 janvier 2015

Internal API design for a merge sort implementation in c


I am thinking of how best to write APIs for a merge sort implementation in C. The external API should be something like int sort(int* data, int length)

I am wondering whether to use the same input data array as the output or to create another array and return it. My gut instinct is to use the same array.


My question is mainly focused on the internal APIs I can write to do this.



void split(int* input, int start, int end) This takes an array input, and then uses the start and end variables to further split it to be merged eventually


int* output merge(int*x, int lengthX, int*y, int lengthY) This will take two sorted arrays as input and merge them, and return the output.


I didnt really like the split API interface. How better could I write this? Is there a canonical reference for merge sort in





Aucun commentaire:

Enregistrer un commentaire