Write programs for Bubble Sort, Quick sort

Answer Posted / naveen

Program for Bubble sort*/
#include<stdio.h>
#include<conio.h>
#define max 20
void insert(int [],int);
void display(int [],int);
void sort(int [],int);
void main()
{
int a[max],n;
clrscr();
printf("\n \t Enter the size of array < %d--->",max);
scanf("%d",&n);
insert(a,n);
printf("\n \t Elements before sorting");
display(a,n);
sort(a,n);
printf("\n \t Elements after sorting");
display(a,n);
}
void insert(int a[],int n)
{
int i;
printf("\n \t Enter %d elements-->",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display(int a[],int n)
{
int i;
for(i=0;i<n;i++)
printf("\n %d",a[i]);
}
void sort(int a[],int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])as
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} }
}}

Enter the size of array < 20---->5

Enter 5 elements--->45
3
78
43
21

Elements before sorting
45
3
78
43
21
Elements after sorting
3
21
43
45
78

Is This Answer Correct ?    23 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is best book for data structures?

712


Which is the parent class of enumset class?

742


Write the algorithm for converting infix expression to postfix expression?

718


Which is the parent class of printerstatereasons class?

672


How many types of lists are there?

687


Does hashmap allow null keys?

632


State the advantages of using postfix notations?

762


Is hashmap fail safe?

705


What is a subtree?

699


What is data structure and its operations?

630


Write a recursive c function to calculate the height of a binary tree.

675


How can avl tree be useful in all the operations as compared to binary search tree?

659


Write program for Bubble Sort ?

759


What is stack algorithm?

630


What are the major data structures used in the following areas : network data model & hierarchical data model?

775