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

How are elements stored in hashset?

465


Is array static or dynamic?

475


How to sequentially represent max-heap?

524


How is a hashset implemented?

473


There is a program which inserts and deletes node in a sorted singly linked list. There is a bug in one of the modules, how would you debug it?

1315






What do you understand by stable sort?

534


Does list allow null values?

490


Is null a binary search tree?

480


Is array part of collection framework?

488


Can we give size to arraylist?

499


What are the average and worst time complexity in a sorted binary tree is

534


What is difference between hashtable and hashmap?

512


Explain the Queue

583


Explain the implementation of an AVL tree and Binary tree.

517


What are the advantages of linked list over array (static data structure)?

683