Skip to main content

Featured

functions in Python

Sorting 2-D array of strings using Bubble Sort


//The following program sorts the 2-D array of strings using bubble sort technique 
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main( )
{
clrscr();
int i,j;
char days[7][10]={"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY",
"FRIDAY","SATURDAY"};
char temp[10];

for(i=1;i<=7;i++)
{
for(j=0;j<6;j++)
{
 if(strcmp(days[j],days[j+1])>0)
 {
 strcpy(temp,days[j]);
 strcpy(days[j],days[j+1]);
 strcpy(days[j+1],temp);
 }
}
}
cout<<"\n\n";

for(i=0;i<7;i++)
cout<<days[i]<<endl;
getch();
}

OUTPUT:
Sorting 2-D array of strings



Comments

  1. Good post. My only suggestion is to remove conio.h header file and clrscr() as they are not supported by some compiler like code blocks and dev c++ and is also not supported in linux. Doing this will make your post reach more people.
    Please see this : Pattern programs in c

    ReplyDelete

Post a Comment

Popular Posts