Search

Bubble Sort in C language

#include
#include
#define N 5
int V[N];
void input(int V[N]);
void sort(int V[N]);
void display(int V[N]);
void main()
{
clrscr();
input(V);
sort(V);
display(V);
getch();
}

void input(int V[N])
{
printf("\n\t****** Enter data tot he array ******\n\n\n");
for(int i=0;i < N;i++)
{
printf("\nEnter value positon %d to the array : ",i+1);
scanf("%d",&V[i]);
}
}

void sort(int V[N])
{
int temp,flag=0;
for(int i=1;i < N;i++)
{
for(int j=0;j < (N-i);j++)
{
if(V[j]>V[j+1])
{
temp=V[j];
V[j]=V[j+1];
V[j+1]=temp;
flag=1;
}
}
if(flag==0)break;
}
}

void display(int V[N])
{
printf("\n\n\n\n\t****** Sorted Array ******\n");
for(int i=0;i < N;i++)
{
printf("\n%d",V[i]);
}
}

No comments:

Post a Comment

Java Interfaces vs. Abstract class

Summary of the similarities and differences between the Interfaces and Abstract class Abstract class Interface Has a constructor Yes No An i...