Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 107,669 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 1,036 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



java assignment

 
Reply to this topicStart new topic

java assignment, sorting in java

blessing inyang
post 2 Jul, 2008 - 04:12 AM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 1

1. Implement and test a class containing a method to perform the selection sort on an array of integers. Make full use of the lecture materials that give details of how to do this.
2. Implement and test a class containing a method to perform the bubble sort on an array of integers. Make full use of the lecture materials that give details of how to do this.


import java.util.*;
class Sort{
public static void main(String[] args) {
int[] intArray = new int[] {7, 2, 6, 3, 8, 4, 9, 1,10,5 };

for (int x : intArray) {
System.out.print(x);
}
System.out.println();
selectionSort(intArray);

for (int x : intArray) {
System.out.println(x);
}

}

public static void selectionSort(int[] intArray) {
for (int out = 0; out < intArray.length - 1; out++) {
int min = out;
for (int in = out + 1; in < intArray.length; in++)
if (intArray[in] < intArray[min])
min = in;
swap(intArray, out, min);
}
}

private static void swap(int[] intArray, int one, int two) {
int temp = intArray[one];
intArray[one] = intArray[two];
intArray[two] = temp;
}
}
User is offlineProfile CardPM

Go to the top of the page


gl3thr0
post 2 Jul, 2008 - 05:13 AM
Post #2


D.I.C Head

**
Joined: 27 Oct, 2007
Posts: 177


My Contributions



Go back and edit ur post and:
  1. Post your code like this: code.gif
  2. Explain what errors or problems u are experiencing
  3. How we can help u

thanks
User is offlineProfile CardPM

Go to the top of the page

pbl
post 2 Jul, 2008 - 03:30 PM
Post #3


D.I.C Lover

Group Icon
Joined: 6 Mar, 2008
Posts: 1,883



Thanked 111 times

Dream Kudos: 75
My Contributions


There are examples of Sorts of all sorts in the Code Snippets
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/29/08 11:05PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month