Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by sort ( 7 years ago )
#include <iostream>
#include <string>
using namespace std;

void swap(string& str1, string& str2)
{
	string t;
	t = str1;
	str1 = str2;
	str2 = t;
}

void sortStrs(string* strings)
{
	for(int i = 0; i < 5; ++i)
	{
		for(int j = i+1; j < 5; ++j)
		{
			if(strings[i] > strings[j])
				swap(strings[i], strings[j]);
		}
	}
}

int main()
{
	string strings[5] = {"ted", "roger", "nick", "albert", "bob"};

	sortStrs(strings);	

	for(int i = 0; i < 5; ++i)
		cout << strings[i] << endl;

	return 0;
}

 

Revise this Paste

Your Name: Code Language: