Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ListTest {
- private final int SIZE = 10;
- int v1,v2;
- public ListTest(){
- List<Integer> l = new List<Integer>();
- for (int i=1;i<=SIZE ;i++ ) {
- l.append((int)(Math.random()*10000));
- }
- l.toFirst();
- for (int a = 0;a<SIZE ;a++ ) {
- System.out.println(a+ ": "+l.getContent());
- l.next();
- } // end of for
- qsort(l,0,SIZE-1);
- System.out.println("---------------------------------");
- l.toFirst();
- for (int a = 0;a<SIZE ;a++ ) {
- System.out.println(a+ ": "+l.getContent());
- l.next();
- } // end of for
- }
- public void qsort(List<Integer> F, int u, int o){
- int l = u, r = o;
- if (o>u) {
- //int p = F[(u+o)/2];
- int p = findP(F,u,o);
- while (l <= r) {
- //while (l<o && F[l]<p)++l;
- //while (r> u && F[r]>p) --r;
- while (l<o && findFl(F,l)<p)++l;
- while (r> u && findFr(F,r)>p) --r;
- if (l<=r) {
- swap(F,l,r);
- ++l;
- --r;
- } // end of if
- } // end of while
- if (u<r) qsort(F,u,r);
- if (l<o) qsort(F,l,o);
- } // end of if
- }
- public int findP(List<Integer> l,int u,int o){
- int pZ = (u+o)/2;
- int pP = 0;
- l.toFirst();
- for (int a = 0;a<pZ ;a++ ) {
- pP = l.getContent();
- l.next();
- } // end of for
- return pP;
- }
- public int findFl(List<Integer> f,int l){
- int pL = 0;
- f.toFirst();
- for (int a = 0;a<l ;a++ ) {
- pL = f.getContent();
- f.next();
- } // end of for
- return pL;
- }
- public int findFr(List<Integer> f,int r){
- int pR = 0;
- f.toFirst();
- for (int a = 0;a<r ;a++ ) {
- pR = f.getContent();
- f.next();
- } // end of for
- return pR;
- }
- public void swap(List<Integer> F, int l, int r ){
- int sR = findFr(F,r);
- int sL = findFl(F,l);
- F.toFirst();
- for (int a = 0;a<r-1 ;a++ ) {
- F.next();
- } // end of for
- F.setContent(sL);
- F.toFirst();
- for (int a = 0;a<l-1 ;a++ ) {
- F.next();
- } // end of for
- F.setContent(sR);
- }
- public static void main(String[] args) {
- new ListTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement