/**
Program Name: BUBBLE SORT
Description: This Program sorts a Given Array in Ascending Order
Author: Tauqirul Haque
*/
#define SIZE 10
void bubbleSort(int data[SIZE]);
void displayElement(int data[SIZE]);
void main()
{
int data[SIZE] = { 45,34,66,89,45,34,76,22,79, 12};
printf("\nThe Original Array Before Sorting ... ");
displayElement(data);
printf("\nArray After Sorting ... ");
bubbleSort(data);
displayElement(data);
}
void displayElement(int data[SIZE])
{
int i;
for(i=0; i
{
printf("\nData[%d] = %d",i,data[i]);
}
printf("\n");
}
void bubbleSort(int data[SIZE])
{
int i,j;
for(i=0; i
{
for(j=0; j
{
if(data[j] > data[j+1]) //swapping
{
int temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
}
}
}
}
Program Name: BUBBLE SORT
Description: This Program sorts a Given Array in Ascending Order
Author: Tauqirul Haque
*/
void bubbleSort(int data[SIZE]);
void displayElement(int data[SIZE]);
void main()
{
int data[SIZE] = { 45,34,66,89,45,34,76,22,79, 12};
printf("\nThe Original Array Before Sorting ... ");
displayElement(data);
printf("\nArray After Sorting ... ");
bubbleSort(data);
displayElement(data);
}
void displayElement(int data[SIZE])
{
int i;
for(i=0; i
{
printf("\nData[%d] = %d",i,data[i]);
}
printf("\n");
}
void bubbleSort(int data[SIZE])
{
int i,j;
for(i=0; i
{
for(j=0; j
{
if(data[j] > data[j+1]) //swapping
{
int temp = data[j];
data[j] = data[j+1];
data[j+1] = temp;
}
}
}
}
Comments