SORTING #include<stdio.h> #include<conio.

h> void main() { int a[10],i,n,j,t; clrscr(); printf("enter size of array: "); scanf("%d",&n); printf(" enter array elements: "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf(" array before sorting\n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("\n after sorting\n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } getch(); } BUBBLE #include<stdio.h> #include<conio.h> void bubble(int a[],int n) { int i,j,t; for(i=n-2;i>=0;i--) { for(j=0;j<=i;j++) { if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t;

n).i. for ( c = 0 .i<=n-1.1 . scanf("%d".i++) printf("%3d". printf("\n\n Enter integer value for total no. clrscr(). printf("\n\n Finally sorted array is: "). c < n . . c >= position . n.&a[i]).i++) { printf("\n\n Enter integer value for element no. } //end program. &position).} } }//end for 1. void main() { int a[100]. /* Insertion #include <stdio. printf("Enter number of elements in array\n"). printf("Enter %d elements\n". &n). position.n. scanf("%d".h> main() { int array[100]. }//end function. scanf("%d". scanf("%d".i+1). value.) array[c+1] = array[c]. scanf("%d". &value).1 .%d : ". printf("Enter the value to insert\n"). printf("Enter the location where you wish to insert an element\n"). n). for ( c = n . c-. c++ ) scanf("%d".a[i]). for( i=0.s of elements to be sorted: "). c.&n). } bubble(a. &array[c]).i<=n-1. for( i=0.

for( c = 0 .array[position-1] = value. array[c]). printf("Resultant array is\n"). . return 0. c++ ) printf("%d\n". c <= n .

Sign up to vote on this title
UsefulNot useful