Program to short the array using the bubble sort in c


Posted Date:     Total Responses: 0    Posted By: R.K. GURU   Member Level: Silver   Points/Cash: 5   


//Developed by R.K.Gour

#include
#include
#include
void bubble_sorti(int[],int); //function prototype
void bubble_sortd(int[],int); //function prototype
void main()
{
int a[20],i,n,index,ch;
char b;
clrscr();
a:
cout<<"\n\n\t\t****MENU****";
cout<<"\n1.TO SORT THE ARRAY IN ASCENDING ORDER";
cout<<"\n2.TO SORT THE ARRAY IN DESCENDING ORDER";
cout<<"\n3.EXIT";
cout<<"\n\nENTER YOUR CHOICE ";
cin>>ch;
switch(ch)
{
case 1:cout<<"\n\nENTER THE NUMBER OF ELEMENTS (MAXIMUM 20)::";
cin>>n;
cout<<"\nENTER THE ARRAY ELEMENTS \n";
for(i=0;i {
cin>>a[i];
}
bubble_sorti(a,n); //function calling
cout<<"\n\nTHE SORTED ARRAY IS SHOWN AS:: ";
for(i=0;i {
cout< }
break;
case 2:cout<<"\n\nENTER THE NUMBER OF ELEMENTS (MAXIMUM 20)::";
cin>>n;
cout<<"\nENTER THE ARRAY ELEMENTS \n";
for(i=0;i {
cin>>a[i];
}

bubble_sortd(a,n);
cout<<"\n\nTHE SORTED ARRAY IS SHOWN AS:: ";
for(i=0;i {
cout< }
break;
case 3:exit(0);
break;
default :cout<<"\nWRONG CHOICE";
cout<<"\nDO YOU WANT TO CONTINUE, ENTER (Y/N):";
cin>>b;
if(b=='y'||b=='Y')
goto a;
break;
}
getch();
}
//***************************************************************
void bubble_sorti(int a[],int size) //function definition
{
getch();
clrscr();
int temp,ctr=0;
for(int i=0;i {
for(int j=0;j<(size-1)-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout<<"\nTHE ARRAY AFTER THE ITERATION :"<<++ctr<<" IS ::";
for(int k=0;k {
cout< }
}
}
}
void bubble_sortd(int a[],int size) //function definition
{
getch();
clrscr();
int temp,ctr=0;
for(int i=0;i {
for(int j=0;j<(size-1)-i;j++)
{
if(a[j] {
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout<<"\nTHE ARRAY AFTER THE ITERATION :"<<++ctr<<" IS ::";
for(int k=0;k {
cout< }
}
}
}

//**************************************************************************



















Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: Screen Programming Project - SAP
Previous Project: Using System Fields along with Case Statements

Return to Project Index

Post New Project


Related Projects


Complete the action items below to enter to win an iPad Mini from India Study Channel! in India Study Channel - Locker on LockerDome
Awards & Gifts
Active Members
TodayLast 7 Daysmore...

 
ISC Technologies, Kochi - India. © All Rights Reserved.