BeispielProgramm-alphapetisches Sortieren-Programmierstil
-
Nun ja. Ich vermende winXP und have es mit Dev C++ 5 kompiliert. Würde auch gerne wissen, wo da das Problem steckt. Wer helfen kann....
-
#include <iostream> #include <string> //#include<locale> using namespace std; void sortieren(string* StrPtr, int anzahl){ bool flag = true; while(flag){ flag = false; for (int i = 0; i < anzahl-1; ++i) if (StrPtr[i] > StrPtr[i+1]){ swap(StrPtr[i], StrPtr[i+1]); swap(StrPtr[i+anzahl], StrPtr[i+anzahl+1]); flag = true; } } } int main() { // locale loc ("German_Germany"); int anzahl; cout << "Wie viele Worte wollen Sie alphabetisch sortieren? "; cin >> anzahl; if (!anzahl) return 0; string* StrPtr = new string [anzahl*2]; cout<<"Bitte geben Sie nun die Worte ein; bestaetigen Sie jedes Wort mit Enter: "<<endl; for (int i = 0; i < anzahl; ++i){ cin >> StrPtr[i]; StrPtr[i+anzahl] = StrPtr[i]; for(size_t x = StrPtr[i].size(); x; --x) StrPtr[i][x-1] = tolower((int)StrPtr[i][x-1]);//<---------- } sortieren(StrPtr, anzahl); for (int i = 0; i < anzahl; i++) cout << endl << StrPtr[i+anzahl]; cout << endl; delete[] StrPtr; return 0; }
So läufts jetzt auch mit GCC-Compiler.
-
Vom feinsten. Nun funktioniert es bei mir auch. Soweit ist denke ich auch alles richtig. Jetzt kann ich mich ranmachen und mir die ganzen templates und so angucken.