/* http://native-code.blogspot.com */ #include<stdio.h> #include<conio.h> #define MAX 20 void input(int*, int); void bubble_sort(int*, int); void display(int*, int); void main() { int a[MAX], max; printf("/* http://native-code.blogspot.com */ \n\n Enter the maximum range:\n"); scanf("%d", &max); printf("\nEnter the Elements:\n"); input(a, max); printf("\nBefore sorting:\n"); display(a, max); bubble_sort(a, max); printf("\nAfter Sorting:\n"); display(a, max); getch(); } void input(int a[], int max) { int i; for(i=0; i<max; i++) scanf("%d", &a[i]); } void display(int a[], int max) { int i; for(i=0; i<max; i++) printf("%d ", a[i]); } void bubble_sort(int a[], int max) { int i, j, temp; for(i=0; i<max-1; i++) { for(j=i+1; j<max; j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } } /* http://native-code.blogspot.com */
Home
» Array
» bubble-sort
» C
» data-structure
» Sorting
» How to perform Bubble Sort program in an integer array?
Post a Comment