Write a Modular C Programming code for Bubble Sort Algorithm DSA
CODE:
#include<stdio.h> bubble(int a[10000],int n) { int temp; for(int i=0;i<n-1;i++){ for(int j=0;j<n-i-1;j++){ if(a[j]>a[j+1]){ temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } printf("\n\nSorted array is: "); print(a,n); } print(int a[10000],int n) { for(int i=0;i<n;i++){ printf("%d ",a[i]); } } main() { int n,a[1000]; printf("Enter the size: "); scanf("%d",&n); printf("Enter Numbers: "); for(int i=0;i<n;i++){ a[i]=(rand()%200); } print(a,n); bubble(a,n); }
OUTPUT
Enter the size: 15 Enter Numbers: 41 67 134 100 169 124 78 158 162 64 105 145 81 27 161 Sorted array is: 0 27 41 64 67 78 81 100 105 124 134 145 158 161 162 Process returned 0 (0x0) execution time : 1.691 s Press any key to continue.
Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page: