mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
Create BubbleSort.c
This commit is contained in:
parent
fa7b073138
commit
11fa9a1c5f
35
BubbleSort.c
Normal file
35
BubbleSort.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ALGORITHM
|
||||
1. Start from left hand side
|
||||
2. Compare first two numbers
|
||||
3. If first_number > second_number than swap both number position. And if first_number < second_number than these compare next two numbers i.e. second_number and third_number.
|
||||
4. Step-3 process repeat until there are no more numbers left to compared.
|
||||
*/
|
||||
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
#define SIZE 7
|
||||
int main()
|
||||
{
|
||||
int i,j,temp;
|
||||
int arr[ SIZE ];
|
||||
for(i=0; i<SIZE; i++)
|
||||
{
|
||||
printf("Enter Number : ");
|
||||
scanf("%d",&arr[i]);
|
||||
}
|
||||
for(i=0; i<SIZE ; i++)
|
||||
{
|
||||
for(j=0; j<(SIZE-1)-i; j++)
|
||||
{
|
||||
if( arr[j] < arr[j+1] )
|
||||
{
|
||||
temp=arr[j];
|
||||
arr[j]=arr[j+1];
|
||||
arr[j+1]=temp;
|
||||
}
|
||||
}
|
||||
printf("%d\t",arr[j]);
|
||||
}
|
||||
getch();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user