KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > web > data > MergeSort


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.web.data;
18
19 import java.util.List JavaDoc;
20
21 /**
22  * @author kevinr
23  */

24 public final class MergeSort extends Sort
25 {
26    /**
27     * Constructor
28     *
29     * @param data a the List of String[] data to sort
30     * @param column the column getter method to use on the row to sort
31     * @param bForward true for a forward sort, false for a reverse sort
32     * @param mode sort mode to use (see IDataContainer constants)
33     */

34    public MergeSort(List JavaDoc data, String JavaDoc column, boolean bForward, String JavaDoc mode)
35    {
36       super(data, column, bForward, mode);
37    }
38    
39    
40    // ------------------------------------------------------------------------------
41
// Sort Implementation
42

43    /**
44     * Runs the Quick Sort routine on the current dataset
45     */

46    public void sort()
47    {
48       if (this.data.size() != 0)
49       {
50          // TODO: finish this!
51
//mergesort(this.data, 0, this.data.size() - 1);
52

53          /*a = this.data;
54           
55           int n = a.length;
56           
57           b = new int[(n+1) >> 1];
58           mergesort(0, n-1);*/

59       }
60    }
61    
62    
63    // ------------------------------------------------------------------------------
64
// Private methods
65

66    /*private static Object[] a, b;
67    
68    private static void mergesort(int lo, int hi)
69    {
70       if (lo<hi)
71       {
72          int m=(lo+hi) >> 1;
73          mergesort(lo, m);
74          mergesort(m+1, hi);
75          merge(lo, m, hi);
76       }
77    }
78    
79    private static void merge(int lo, int m, int hi)
80    {
81       int i, j, k;
82       
83       i=0;
84       j=lo;
85       
86       // copy first half of array a to auxiliary array b
87       while (j <= m)
88       {
89          b[i++] = a[j++];
90       }
91       
92       i=0;
93       k=lo;
94       
95       // copy back next-greatest element at each time
96       while (k < j && j <= hi)
97       {
98          if (b[i] <= a[j])
99          {
100             a[k++]=b[i++];
101          }
102          else
103          {
104             a[k++]=a[j++];
105          }
106       }
107       
108       // copy back remaining elements of first half (if any)
109       while (k < j)
110       {
111          a[k++] = b[i++];
112       }
113    }*/

114 }
115
Popular Tags