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

Question #52620
bubble sort java program
Expert's answer
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 first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS
paypal