字符串排序

#include
#include
#include
using namespace std;
int main(void){
	string str[] = { "abc", "ac", "c", "abcd" };
	int length = sizeof(str) / sizeof(str[0]);
	for (int i = 0; i < length; i++)
	{
		for (int j = i+1; j < length; j++)
		{
			if (str[i].size()>str[j].size())
			{
				string temp = str[j];
				str[j] = str[i];
				str[i] = temp;
			}
		}

	}
	for (int i = 0; i < length; i++)
	{
		cout << str[i] << endl;
	}
	system("pause");
	return 0;

}

你可能感兴趣的:(STL(C++),c++数据结构)