Advertisement
Guest User

quicksort

a guest
Nov 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class ListTest {
  2. private final int SIZE = 10;
  3. int v1,v2;
  4. public ListTest(){
  5. List<Integer> l = new List<Integer>();
  6. for (int i=1;i<=SIZE ;i++ ) {
  7. l.append((int)(Math.random()*10000));
  8.  
  9. }
  10. quicksort(l,0,SIZE-1);
  11. }
  12.  
  13. public void quicksort(List<Integer> F, int u, int o){
  14. int l = u, r = o;
  15. if (o>u) {
  16. //int p = F[(u+o)/2];
  17. int p = findP(F,u,o);
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. while (l <= r) {
  35. //while (l<o && F[l]<p)++l;
  36. //while (r> u && F[r]>p) --r;
  37. while (l<o && findFl(F,l)<p)++l;
  38. while (r> u && findFr(F,r)>p) --r;
  39. if (l<=r) {
  40. swap(F,l,r);
  41. ++l;
  42. --r;
  43. } // end of if
  44. } // end of while
  45. if (u<r) qsort(F,u,r);
  46. if (l<o) qsort(F,l,o);
  47. } // end of if
  48.  
  49. }
  50.  
  51.  
  52. public int findP(List<Integer> l,int u,int o){
  53. int pZ = (u+o)/2;
  54. int pP = 0;
  55. l.toFirst();
  56. for (int a = 0;a<pZ ;a++ ) {
  57. pP = l.getContent();
  58. l.next();
  59. } // end of for
  60. return pP;
  61.  
  62. }
  63.  
  64. public int findFl(List<Integer> f,int l){
  65. int pL = 0;
  66. f.toFirst();
  67. for (int a = 0;a<l ;a++ ) {
  68. pL = f.getContent();
  69. f.next();
  70. } // end of for
  71. return pL;
  72.  
  73. }
  74.  
  75.  
  76. public int findFr(List<Integer> f,int r){
  77. int pR = 0;
  78. f.toFirst();
  79. for (int a = 0;a<r ;a++ ) {
  80. pR = f.getContent();
  81. f.next();
  82. } // end of for
  83. return pR;
  84.  
  85. }
  86.  
  87. public void swap(List<Integer> f, int a, int r ){
  88.  
  89.  
  90.  
  91. }
  92.  
  93.  
  94.  
  95. public static void main(String[] args) {
  96. new ListTest();
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement