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

What are dynamic data structures?

661


What is the complexity of sorting algorithm?

511


Does arraylist have a tostring?

511


What is binary tree example?

577


How do you sort an arraylist?

493






Is priority queue sorted?

521


How do you separate zeros from non-zeros in an array?

531


What is the use of isEmpty() member methods?

536


What are the difference between arraylist and linkedlist from the perspective of sorting?

560


Which data structure is used to perform recursion?

505


What is sorting rule in shapes?

477


How do you find the complexity of a bubble sort?

479


Describe what is Node in link list? And name the types of Linked Lists?

542


State the difference between stacks and linked lists?

535


What are binary trees?

587