Hi,

Im new to java

im trying to study sorting methods specifically bubble sorting

i found this code online but couldn't understand what it means. can someone kindly comment the codes so I can uderstand it well.

TIA

here's the code

public static void sort( int a[], int n )   		// Bubble Sorting //
	  {
	  int i, j,t=0;
	  	for(i = 0; i < n; i++)
	 	 {
	  		for(j = 1; j < (n-i); j++)
	  			{
	  			if(a[j-1] > a[j])
	  			{
				  t = a[j-1];
				  a[j-1]=a[j];
				  a[j]=t;
	  			}
	  }
	  }
	  }

Recommended Answers

OK. maybe next time a quick look at the forum guidelines before posting?
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies
You'll find we're quite friendly here, but a bit impatient with people who don't want to do any work themselves.

Jump to Post

All 3 Replies

That's not how these forums work.
Ask for help after you've done some work yourself.
Two minutes with Google will give you all the information you could possibly want on bubble sorts in Java.

Sorry man, im just new here. I already got it btw. sorry for the bother

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.