Answer to Question #52620 in Java | JSP | JSF for adem

Question #52620
bubble sort java program
1
Expert's answer
2015-06-01T01:45:33-0400
Solution.

public class MainClass {

public static void main(String[] args) {

int temp;

// test array
int num[]={5,9,5,7,1,3,4,9,2,5,7,6};

System.out.println("Unsorted array:");

for (int i = 0; i < num.length; i++)
System.out.print(num);


//Bubble Sort
for (int i = num.length; i > 0; i--)
{
for (int j = 1; j < i; j++)
{
if (num[j] < num[j-1])
{
temp=num[j];
num[j]=num[j-1];
num[j-1]=temp;

} // end if
} // end for(j)
} // end for(i)


System.[i]out
.println("\n\nSorted array:");

for (int i = 0; i < num.length; i++)
System.out.print(num[i]);
}

}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS