Implement the following sorting techniques to sort a given list of integers in ascending order (i) Bubble sort

 /* bubble sort*/

#include<stdio.h>

void bsort(int a[],int n);

int main()

{

int a[10],i,n;

clrscr();

printf("\n enter no of elements:");

scanf("%d",&n);

printf("\n enter %d elements:",n);

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

}

bsort(a,n);

return 0;

}

void bsort(int a[],int n)

{

int i,j,k,t;

for(i=0;i<n;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("\n after pass %d:",i+1);

for(k=0;k<n;k++)

printf("%d\t",a[k]);

}

printf("\n final order:\n");

for(i=0;i<n;i++)

printf("%d\t",a[i]);

}

Comments

Popular posts from this blog

Create a Binary Search Tree of integers and perform the following operations (i)insert (ii) delete (iii). Search (iv) traversals (pre-order, in-order, post-order) BST

Creation Of DLL

Develop non-recursive functions to perform search for a Key value in a given list using (i) Binary Search Non Recursive