Vlad and I were thinking along the same lines. This is easy but may not be
the best for commercial applications.
Here is a simple program I just wrote:
class CraigsVectorSort {
Vector vec = new Vector();
public static void main(String[] args) {
CraigsVectorSort v = new CraigsVectorSort();
v.arraySimpleSort();
}
void arraySimpleSort() {
vec.add(new String("abbot"));
vec.add(new String("silium"));
vec.add(new String("randy"));
vec.add(new String("goofy"));
vec.add(new String("zenia"));
vec.add(new String("pokie"));
vec.add(new String("xylaphone"));
vec.add(new String("dogface"));
vec.add(new String("friggen-joe"));
vec.add(new String("penuckle"));
vec.add(new String("charlie"));
vec.add(new String("manna"));
System.out.println("before: " + vec);
Object[] obArr = vec.toArray();
Arrays.sort(obArr);
vec.removeAllElements();
for (int i = 0; i < obArr.length; i++) {
vec.add(obArr[i]);
}
obArr = null;
System.out.println("after :0) : " + vec);
}
}
It works efficiently. You may want to consider using one of the collections
rather then Vector. You may not need the synchronization so an ArrayList
would be faster. Many many considerations.
Let me know what you think.
Regards,
Craig O'Brien
Java Programmer/Web Developer
[EMAIL PROTECTED]
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 02, 2001 6:40 PM
To: [EMAIL PROTECTED]
Subject: Re: QuickSorting Vectors
Don't have a sample but you can
take a look at the java.util.Arrays's sort(Object[]) method.
May be you can use that in combination with Vector.toArray()
which calls System.arraycopy, so this should be fast, may be
even faster than iterating over Vector's elements during
custom sort if you decide to sort Vectors directly.
method...
--V.
Ryan wrote:
>
> I am a student but this is not for a class.. I am trying to keep a thread
> running that holds files in a directory. I just want to maximize my
bandwith
> and CPU usage for my web site.
>
> -ryan
>
> ----- Original Message -----
> From: "Stefán F. Stefánsson" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, March 02, 2001 5:21 PM
> Subject: RE: QuickSorting Vectors
>
> > R U a student?
> >
> > When is the deadline?
> >
> > -----Original Message-----
> > From: Ryan [mailto:[EMAIL PROTECTED]]
> > Sent: 3. mars 2001 00:46
> > To: [EMAIL PROTECTED]
> > Subject: QuickSorting Vectors
> >
> >
> > Does anyone have a quicksorting class that sorts Vectors containing
> > Strings that wouldn't mind letting me look at?
> >
> >
> > -ryan
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, email: [EMAIL PROTECTED]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]