Function Sortiraj() should sort the array of Strings using the selection sort technique but It does not work because program just crashes when it tries to compare two strings with > .
So does anybody have already written function for sorting array of strings.
I would really appreciate if someone would give me an example for sorting array of strings.
(Note: I don't want char * sorting I want string sorting)
Also are there already made sorting functions in C++ (I've hear of qsort but I don't know how to use it also show me some examples of array sorting methods)
void Citaj()
{
fstream fajl("in.txt",ios::in);
fajl >> N; fajl.get(); // <- add this here...
//...to get rid of the newline character,
//or the first getline will read an empty string
//...
}
void Sortiraj()
{
//Selection sort
string pom;
for (int i = 1; i <= N-1; i++)
{
//careful here, you need j, not ifor(int j=i+1; i <= N; j++)
{
//don't do it like this.
//copy stari to novi first
//in a separate function
//and then sort novi
if(stari[i] > stari[j])
{
pom = stari[i];
novi[i] = stari[j];
stari[j] = pom;
}
}
}
}