Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

algorithm psudocode trouble coding it to java

 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey all, im struggling abit with some psudocode that i have to convert to java. basically im writing a quicksort algorithm which i have been supplied the psudocode for. but im having trouble analysing the psudocode on what part of it.

the bit i am stuck on is it says:

swap(A,pL,pR)

with A being the array of integers i have, and pL and pR being integers of some sort. here is the full psudocode; it is to partition the array before sorting:





the code i have got for it so far is:



does anybody have any idea?
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means you write a swap() method and call it from that if block.
 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
right, but what exactly am i swapping?! :s
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. Try the elements of the array pointed to by the numbers "left" and "right"

Or Google for quicksort and you are bound to find the algorithm explained. I can't remember the details of quicksort. If you do Google you will find (inter alia) this, this and this. You will probably understand the first two of those links
 
Jeff Yan
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok cheers mate
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome, and good luck with it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic