Introduction to Programming (for MCS)
Thursday, April 09, 2009 Posted In CS and IT Edit This#include
#include
using namespace std;
void swap(string*, int ,int );
void sort(string*);
int main(){
string strings[5];
for(int i=0;i<5;i++)//taking user input
{
cout<<"Enter String "<cin>>strings[i];
}
sort(strings);//calling sort function
for(int i=0;i<5;i++){//print names
cout<
cout<
}
void swap(string *str, int i, int j)
{
string temp;
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
void sort (string *str)
{
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(str[i].compare(str[j]) >0)
{
swap(str, i, j);
}
}
}
}