Introduction to Programming (for MCS)

No Comments
#include

#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);

}

}

}

}
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment