X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2FMCview%2FZsort.java;h=8325f9a5d468ad10cf2a62581ad4c8d92e53bcf7;hb=5951e3b0b9faea1c8b54914cb64ff3a08ba27cb6;hp=215f75321207b129c1ab495ba26cb9a821e5f700;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/MCview/Zsort.java b/src/MCview/Zsort.java index 215f753..8325f9a 100755 --- a/src/MCview/Zsort.java +++ b/src/MCview/Zsort.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer -* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -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 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 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 int partition(Vector bonds, int p, int r) { + float x = ((Bond) bonds.elementAt(p)).start[2]; + int i = p - 1; + int j = r + 1; + Bond tmp; + while (true) { + do { + j --; + } while ((j >= 0) && (((Bond) bonds.elementAt(j)).start[2] > x)); + + do { + i ++; + } while ((i < bonds.size()) && + (((Bond) bonds.elementAt(i)).start[2] < x)); + + if (i < j) { + tmp = (Bond) bonds.elementAt(i); + bonds.setElementAt(bonds.elementAt(j), i); + bonds.setElementAt(tmp, j); + } else { + return j; + } + } } - } } - - -