X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FZsort.java;h=322fd2a0466428f306f45a3ee6cb5a6c7aebb304;hb=588042b69abf8e60bcc950b24c283933c7dd422f;hp=215f75321207b129c1ab495ba26cb9a821e5f700;hpb=5cd8e373c75fb348ecda4d94d8a46468fb92756d;p=jalview.git diff --git a/src/MCview/Zsort.java b/src/MCview/Zsort.java index 215f753..322fd2a 100755 --- a/src/MCview/Zsort.java +++ b/src/MCview/Zsort.java @@ -16,54 +16,48 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ - package MCview; import java.util.*; -public class Zsort { - - public static void Zsort(Vector bonds) { - - sort(bonds,0,bonds.size()-1); - } - - - - public static void sort(Vector bonds,int p, int r) { - int q; - if (p < r) { - q = partition(bonds,p,r); - sort(bonds,p,q); - sort(bonds,q+1,r); +public class Zsort { + public static void Zsort(Vector bonds) { + sort(bonds, 0, bonds.size() - 1); } - } - - private static int partition(Vector bonds, int p, int r) { - float x = ((Bond)bonds.elementAt(p)).start[2]; - int i = p-1; - int j = r+1; - while(true) { - do { - j = j-1; - } while (j >= 0 && ((Bond)bonds.elementAt(j)).start[2] > x); + public static void sort(Vector bonds, int p, int r) { + int q; - do { - i = i+1; - } while (i < bonds.size() && ((Bond)bonds.elementAt(i)).start[2] < x); + if (p < r) { + q = partition(bonds, p, r); + sort(bonds, p, q); + sort(bonds, q + 1, r); + } + } - if ( i < j) { - Bond tmp = (Bond)bonds.elementAt(i); - bonds.setElementAt(bonds.elementAt(j),i); - bonds.setElementAt(tmp,j); - } else { - return j; - } + private static int partition(Vector bonds, int p, int r) { + float x = ((Bond) bonds.elementAt(p)).start[2]; + int i = p - 1; + int j = r + 1; + + while (true) { + do { + j = j - 1; + } while ((j >= 0) && (((Bond) bonds.elementAt(j)).start[2] > x)); + + do { + i = i + 1; + } while ((i < bonds.size()) && + (((Bond) bonds.elementAt(i)).start[2] < x)); + + if (i < j) { + Bond tmp = (Bond) bonds.elementAt(i); + bonds.setElementAt(bonds.elementAt(j), i); + bonds.setElementAt(tmp, j); + } else { + return j; + } + } } - } } - - -