Write programs for Bubble Sort, Quick sort

Answer Posted / cynthia

//Program for implementing Bubble Sort

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],n,i,p,t;
clrscr();
printf("Enter the array limit");
scanf("%d",&n);
printf("\nEnter %d elemts",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
p=0;
while(p<n-i)
{
if(a[p]>a[p+1])
{
t=a[p];
a[p]=a[p+1];
a[p+1]=t;
}
p++;
}
}
for(i=0;i<n;i++)
printf("%5d",a[i]);
getch();
}

Is This Answer Correct ?    42 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does treemap preserve order?

613


Can arraylist contain null?

630


What are the properties of an algorithm?

698


Explain the applications of stack?

713


How is a queue works?

713


What is difference between hashset and treeset?

731


What do you mean by data and data structure?

699


How does a hashmap work?

674


What do you mean by rehashing?

759


What is difference between hashmap and map?

653


Does concurrenthashmap allow null?

663


How to find the duplicate in an array?

689


Do all declaration statements result in a fixed reservation in memory?

688


What is data structure and data type?

729


What is the heap in data structures?

711