Untitled
unknown
plain_text
a year ago
1.0 kB
5
Indexable
#include<stdio.h>
#include<conio.h>
void BubbleSort(int[],int);
void print(int[],int,int);
void BubbleSort(int list[],int size)
{
int i,j,temp;
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(list[j]>list[j+1])
{
temp=list[j];
list[j]=list[j+1];
list[j+1]=temp;
}
}
printf("\n\n\t\t\t\tList after %d iteration :",i);
print(list,size,size-i-1);
}
}
void print(int list[],int size,int mark)
{
int i;
for(i=0;i<size;i++)
{
if(i==mark)
printf("[");
printf("%d",list[i]);
printf(" ");
}
printf("]");
}
int main()
{
int list[20],size,i;
printf("\n\nEnter the size of the list:");
scanf("%d",&size);
/*Read the element from the user*/
printf("\n\nEnter the element :\n\n\n");
for(i=0;i<size;i++)
scanf("%d",&list[i]);
printf("\n\nList before sorting:");
print(list,size,0);
/*Sort the element using bubble sort*/
BubbleSort(list,size);
printf("\n\nSorted list:");
print(list,size,0);
printf("\n\n\n");
return 0;
}
Editor is loading...
Leave a Comment