Methods Summary |
---|
public static void | main(java.lang.String[] args)
Vector v1 = new Vector();
//Vector v2 = new Vector();
//Vector v3 = new Vector();
v1.addElement("aaaa");//NOI18N
v1.addElement("zzzz");//NOI18N
v1.addElement("dddd");//NOI18N
v1.addElement("ccccx");//NOI18N
v1.addElement("cccc");//NOI18N
v1.addElement("cccc");//NOI18N
v1.addElement("cccc");//NOI18N
v1.addElement("bbbb");//NOI18N
print(v1, "****** before");//NOI18N
sort(v1);
print(v1, "\n******after");//NOI18N
|
private static void | mergeSort(com.sun.enterprise.tools.common.SorterObject[] arr)
int low = 0;
int high = arr.length;
for (int i = low; i < high; i++)
{
for (int j = i; j > low && arr[j-1].sortName.compareTo(arr[j].sortName) > 0; j--)
{
swap(arr, j, j-1);
}
}
|
private static void | print(java.util.Vector v, java.lang.String s)
System.out.println(s + "\n");//NOI18N
for(Enumeration e = v.elements(); e.hasMoreElements(); )
{
System.out.println("" + e.nextElement());//NOI18N
}
|
public static void | sort(java.util.Vector v)
if(v.size() <= 1)
return;
SorterObject[] arr = new SorterObject[v.size()];
Enumeration e = v.elements();
for(int i = 0 ; e.hasMoreElements() ; i++)
{
arr[i] = new SorterObject(e.nextElement());
}
mergeSort(arr);
v.removeAllElements();
for(int i = 0; i < arr.length; i++)
{
v.addElement(arr[i].obj);
}
|
private static void | swap(com.sun.enterprise.tools.common.SorterObject[] x, int a, int b)
SorterObject t = x[a];
x[a] = x[b];
x[b] = t;
|