Browse Source

Создана ветвь

Настя 5 years ago
parent
commit
b7b7c282e2
1 changed files with 44 additions and 0 deletions
  1. 44 0
      src/javaapp1/Sortirovka.java

+ 44 - 0
src/javaapp1/Sortirovka.java

@@ -0,0 +1,44 @@
+package javaapp1;
+
+/**
+ *
+ * @author Настя
+ */
+import java.util.*;
+public class Sortirovka {
+    
+    public ArrayList<Student> quickSort(ArrayList<Student> data, int s){
+        int startIndex = 0;
+        int endIndex = data.size() - 1;
+        doSort(data, s, startIndex, endIndex);
+        return data;
+    }
+    
+    public ArrayList<Student> doSort(ArrayList<Student> data, int s, int start, int end) { 
+        if (start >= end) 
+            return data; 
+        int i = start, j = end; 
+        int cur = i - (i - j) / 2; 
+        while (i < j) { 
+            while (i < cur && ((double)data.get(i).getMark(s) >= (double)data.get(cur).getMark(s))) { 
+                i++; 
+            } 
+            while (j > cur && ((double)data.get(cur).getMark(s) >= (double)data.get(j).getMark(s))) { 
+                j--; 
+            } 
+            if (i < j) { 
+                Student temp = data.get(i); 
+                data.set(i, data.get(j));
+                data.set(j, temp);
+                if (i == cur) 
+                    cur = j; 
+                else if (j == cur) 
+                    cur = i; 
+            } 
+        } 
+        doSort(data, s, start, cur); 
+        doSort(data, s, cur+1, end);
+        return data;
+    }
+    
+}