1

I have a 3D array: float input[2][50][1000];

I want to quick sort it from:

qsort (x, sizeof(x)/sizeof(*x), sizeof(*x), comp);

where comp is

int comp (const void * elem1, const void * elem2) {
    float f = *((float*)elem1);
    float s = *((float*)elem2);
    if (f > s) return  1;
    if (f < s) return -1;
    return 0;
}

I just want to sort 1 dimension of my 3D array, i.e I want to sort input[0][temp][0], input[0][temp][1], input[0][temp][2] and so on.

Ques: What do I replace x with? Forgive me if it sounds stupid

7
  • Ultimately this is to sort 1000 elements from input[0][temp][0]..input[0][temp][999], is that correct ? Commented Apr 12, 2014 at 7:36
  • @WhozCraig That figure may not be equal to thousand but yah that dimension only. It may be less too like till 50. But how does that matter? Commented Apr 12, 2014 at 7:37
  • @WhozCraig Yah that should be float, could you please write an answer. And yah about the 1000 thing, i am declaring it till 1000 but maybe i fill elements upto 100 only and if so i will sort upto 100 only Commented Apr 12, 2014 at 7:39
  • 2
    Sure, item[0][temp] Commented Apr 12, 2014 at 7:46
  • Note: despite the name, qsort() may sort using a different algorithm than "quick sort". Commented Apr 12, 2014 at 7:59

1 Answer 1

1
float (*x)[1000] = &input[0][temp];
qsort (x, sizeof(*x)/sizeof(**x), sizeof(**x), comp);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.