• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sorting 3-dimensional array.  RSS feed

 
Ashish Schottky
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was asked in some of the interview, it sounds fairly simple but I couldnot crack it.
Q] An array say x[][][] is to be sorted in decending order of y[].
Assume int x[][][]=new int[100][7][2];
Assume int y[]=new int[100];

The numbers in last dimension contains pair and should not be separated from each other.
Use any sort algorithm.

What I tried was:

However I am not getting the answer. I am finding it very hard to visualize this.
please help me if you can
 
Campbell Ritchie
Marshal
Posts: 56207
171
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ashish Schottky wrote:. . . I am finding it very hard to visualize this. . . .
I am not surprised. You have posted a mass of code which won't compile, with number literals like 7, and c and ply appearing mysteriously. What is y, which doesn't appear to be part of the array?

You will have to sit down with a pencil and paper and write down what algorithm you would use. Write down what you think "sorting" an array means.

The idea behind such interview tests is to see how you approach a problem. If you simply write impenetrable code they won't offer you the job.
 
Campbell Ritchie
Marshal
Posts: 56207
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too difficult for "beginning". Moving thread.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!