Featured
- Get link
- X
- Other Apps
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 |
- Get link
- X
- Other Apps
Labels:
bubble sort to sort 2-D array of strings in C++
Sorting 2-D array of strings using Bubble Sort
sorting the 2-D array of strings using bubble sort technique
Comments
thanks.
ReplyDeleteGood 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.
ReplyDeletePlease see this : Pattern programs in c