bekovski

ppbs_descr_code

Aug 7th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. // here: pseudo-code
  2. init(Array A, Pivot p)
  3. m1 = 0
  4. foreach(elem in A): if elem < p then m1++
  5. m2 = m1
  6. foreach(elem in A): if elem == p then m2++
  7. i1 = 0
  8. i2 = m1
  9. i3 = m2
  10. while(i1 < m1 and A[i1] < p) i1++
  11. while(i2 < m2 and A[i1] == p) i2++
  12. while(i3 < A.length and A[i3] > p) i3++
  13.  
  14.  
  15. partition(Array A, Pivot p)
  16. until(i1 == m1 and i2 == m2 and i3 == A.length) do:
  17. if i1 < m1
  18. if A[i1] == p
  19. swap A[i1] with A[i2]
  20. while(i2 < m2 and A[i2] == p) i2++
  21. else
  22. swap A[i1] with A[i3]
  23. while(i3 < A.length and A[i3] > p) i3++
  24. while(i1 < m1 and A[i1] < p) i1++
  25. else
  26. swap A[i2] with A[i3]
  27. while(i2 < m2 and A[i2] == p) i2++
  28. while(i3 < A.length and A[i3] > p) i3++
  29. return m1 and m2
Advertisement
Add Comment
Please, Sign In to add comment