• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array sorting using plane java code.  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to java, i faced one interview question "How to sort the list of integers Array by using plane java code",
please help me on this answer.

Note: dont use any Collections.sort() method.

Ex: int a[]={3,5,2,1,7,4}
sort this array by using plane java code.

Thanks,
-------
Laxmi
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, since Collections.sort() is itself just "plain" Java code--that is, no different from something any Java programmer could write himself--you would write a sort method that operates similarly to Collections.sort().

If you didn't study sorting algorithms in your CS education, or don't remember them, you can google for sorting algorithms.
 
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

LaxmiPrasanna Bn wrote:dont use any Collections.sort() method.


See the source code of that. by the way ; if you want simple approach there are lot example, bubble sort, insertion sort, selection sort etc... Please have a look at the techniques.
 
Laxmi Prasanna Bn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for yours clue.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!