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 is a matrix? Explain its uses with an example

568


What is the use of treemap?

476


How do I push an element into a stack?

486


What is an iterative algorithm?

530


What is lifo?

660






Why merge sort is better than insertion sort?

473


Differentiate between iterator and listiterator.

631


Does linked list allow null values?

462


What do you mean by level of the tree?

569


What is b tree in data structure?

479


What things you would care about to improve the performance of application if its identified that its db communication that needs to be improved?

529


Does map extend iterable?

456


Is pointer a variable in data structure?

520


How remove all from arraylist?

483


Is hashmap fail safe?

501