Write programs for Bubble Sort, Quick sort

Answer Posted / siya

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,temp;
printf("\n\nEnter the total number of eleents:");
scanf("%d",&n);
printf("\n\nEnter the array elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
/* sorting */
for(i=0;i<n;i++)
{
for(j=i;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
}
printf("\n\nThe sorted array:");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}

Is This Answer Correct ?    36 Yes 28 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if we try to insert duplicate key in hashmap?

423


Which sorting algorithm is best for large data?

475


Which data structure is used to perform recursion?

501


Can constructor be static?

470


Why arraylist is not efficient for manipulation?

449






What is difference between tree and forest?

520


What is difference between array and arraylist?

518


What is the use of treemap?

484


What are the types of collection?

476


How will you sort the elements of array in descending order?

596


What is default array size?

569


What do you mean by structure property in a heap?

540


Define an equivalence relation?

650


What are the advantages of selecetion sort?

699


What is heap and its types?

500