NeedlessKane
asked on
SelectionSort and BubbleSort algorithims
Hello,
I need the source code for BubbleSort and SelectionSort algorithims that take in a Comparable array as follows:
public static void BubbleSort(Comparable[] a)
{
// code here
}
public static void SelectionSort(Comparable[] a)
{
//code here
}
Thanks
-Taylor
I need the source code for BubbleSort and SelectionSort algorithims that take in a Comparable array as follows:
public static void BubbleSort(Comparable[] a)
{
// code here
}
public static void SelectionSort(Comparable[]
{
//code here
}
Thanks
-Taylor
ASKER
I tried that link earlier objects, I can't get the code to compile.
post the problems, and i'll help resolve them.
ASKER
Ok, well I imported the SortAlgorithim and the SortItem clases, and when I compile SortItem it says i have a depreciated API.
ASKER
All i need is a simple algorithim that uses a Comparable array, I thought it'd be easy to find one online, but my searching has turned up nothing.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//------------------------ ---------- ---------- ------ sort()
// Sort a String array using selection sort.
void sort(String[] a) {
for (int i=0; i<a.length-1; i++) {
for (int j=i+1; j<a.length; j++) {
if (a[i].compareTo(a[j]) > 0) {
String temp=a[j]; a[j]=a[i]; a[i]=temp;
}
}
}
}
// Sort a String array using selection sort.
void sort(String[] a) {
for (int i=0; i<a.length-1; i++) {
for (int j=i+1; j<a.length; j++) {
if (a[i].compareTo(a[j]) > 0) {
String temp=a[j]; a[j]=a[i]; a[i]=temp;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> it says i have a deprecated API
No worries as said by objects. that are related to Thread and awt methods.
SortItem.java:81: warning: size() in java.awt.Component has been deprecated
int a[] = new int[size().height / 2];
^
SortItem.java:82: warning: size() in java.awt.Component has been deprecated
double f = size().width / (double) a.length;
^
SortItem.java:153: warning: size() in java.awt.Component has been deprecated
int y = size().height - 1;
^
SortItem.java:158: warning: size() in java.awt.Component has been deprecated
g.drawLine(arr[i], y, size().width, y);
^
SortItem.java:163: warning: size() in java.awt.Component has been deprecated
y = size().height - 1;
^
SortItem.java:171: warning: size() in java.awt.Component has been deprecated
g.drawLine(0, y, size().width, y);
^
SortItem.java:176: warning: size() in java.awt.Component has been deprecated
g.drawLine(0, y, size().width, y);
^
SortItem.java:213: warning: stop() in java.lang.Thread has been deprecated
kicker.stop();
^
8 warnings
No worries as said by objects. that are related to Thread and awt methods.
SortItem.java:81: warning: size() in java.awt.Component has been deprecated
int a[] = new int[size().height / 2];
^
SortItem.java:82: warning: size() in java.awt.Component has been deprecated
double f = size().width / (double) a.length;
^
SortItem.java:153: warning: size() in java.awt.Component has been deprecated
int y = size().height - 1;
^
SortItem.java:158: warning: size() in java.awt.Component has been deprecated
g.drawLine(arr[i], y, size().width, y);
^
SortItem.java:163: warning: size() in java.awt.Component has been deprecated
y = size().height - 1;
^
SortItem.java:171: warning: size() in java.awt.Component has been deprecated
g.drawLine(0, y, size().width, y);
^
SortItem.java:176: warning: size() in java.awt.Component has been deprecated
g.drawLine(0, y, size().width, y);
^
SortItem.java:213: warning: stop() in java.lang.Thread has been deprecated
kicker.stop();
^
8 warnings
ASKER
I figured out the problem for myself, thanks for all who posted.
Collections.sort(urCollect
?