What is sorting ?
The term sorting means arrangement of element in particular order i.e in ascending or descending order is known as sorting.
Example:: 45,55,25,35,65
Sorted data :: 25,35,45,55,65
How bubble sort work ?
Bubble sort method works on method of comparing two consecutive digits.
45,55,25,35,65
working::
45,55,25,35,65
45,25,55,35,65
25,45,55,35,65
25,45,35,55,65
25,35,45,55,65 ( sorted data )
Program for bubble sort in c
#include<stdio.h>
#include<conio.h>
void main ()
{
int i,j,n,t,a[100];
clrscr ();
printf ("\n Enter size of array:");
scanf ("%d", &n);
printf ("\n Enter element in array:");
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
}
for (i=o;i<n-1;i++)
{
for (j=0;j<n-i-1;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf (sorted array=");
for (i=0;i<n;i++)
{
printf ("\t %d",a[i]);
}
getch ();
}
I am sure this is very useful because I have learnt alot just from reading this sorting.
ReplyDeleteHmmm. Interesting but I really dont understand it!
ReplyDeleteI am sure this will be helpful for a programmer.
ReplyDeleteNo idea programming was this interesting. Thanks
ReplyDeleteI took a programming course in college, it is very complicated.
ReplyDeleteTBH hurts my brain!! Hahah props to you!
ReplyDeleteThanks to your posts, I am starting to get motivated to learn coding. :)
ReplyDeleteThis is really helps to all of beginner programmers! Nice one.
ReplyDeleteGoodness, this is too techy for me
ReplyDeleteOh wow, all but greek to me. But really interested in coding. Thanks a lot for such an informative post.
ReplyDeleteEnglish please....this makes me want to learn coding.....
ReplyDeleteWow this is another level of programming language. Very interesting!
ReplyDeleteI don’t understand this at all. Maybe next time explain it in layman’s terms
ReplyDeleteI don't understand this really ut I know it would be helpful to someone someday.
ReplyDeleteI just stared at this for so long trying to understand lol But i'm sure it's helpful for others.
ReplyDelete