neviem ako je to v C#, ale v C++ by som vzal ascii hodnotu prvého písmena a utriedil ju za pomoci nejakého triedacieho algoritmu (Bubble sort, min sort, selection sort...)
// pridané po 17 minútach od posledného príspevku
Vlatne pri stringu nemusíš porovnávať ascii hodnoty, to už robí on zateba. Musel by si to robiť pri char, ale to by si musel použiť už dvojrozmerné pole.
Kód:
#include <iostream>
#include <string>
using namespace std;
const int n = 7;
void swap(int* a, int* b);
void bubble_sort(string name[]);
int main()
{
string name[n];
name[0] = "Robo";
name[1] = "Aram";
name[2] = "Filip";
name[3] = "Adam";
name[4] = "Fero";
name[5] = "Boris";
name[6] = "Adama";
bubble_sort(name);
for(int i = 0; i < n; i++)
cout<<name[i]<<endl;
system("pause");
return 0;
}
void swap(string* a, string* b)
{
string temp = *a;
*a = *b;
*b = temp;
}
void bubble_sort(string name[])
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n - i - 1; j++)
{
if(name[j] > name[j + 1])
swap(&name[j], &name[j + 1]);
}
}
}