Forum » Programiranje » need help c++
need help c++
kretze ::
zdravo folk kaj lahko kdo pomaga zanima me sicer zakaj mi program pravilno ne "posorta"
#include <iostream> #include <stdlib.h> #include <string> using namespace std; void sortbyexchange(char**person, int n) { int flag; char *temp; for (int i = 0; i < n - 1; i++) { flag = 1; for (int j = 0; j < (n - 1 - i); j++) { if (strcmp(person[j], person[j + 1])>0) { flag = 0; temp = person[j]; person[j] = person[j + 1]; person[j + 1] = temp; } } if (flag); break; } } int main() { int n = 0; char *person[100]; char choice; while (1) { person[n] = new char[40]; cout << "enter name "; cin >> person[n++]; cout << "another one [y/n] "; cin >> choice; if (choice == 'n') break; } cout << "usnsorted list " << endl; for (int i = 0; i < n; i++) cout << person[i] << endl; cout << "sorted list " << endl; sortbyexchange(person, n); for (int i = 0; i < n; i++) cout << person[i] << endl; system("pause"); return 0; }
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | napaka v c++Oddelek: Programiranje | 1916 (1001) | čuhalev |
» | [Qt/C++]problem z Undefined reference na konstanti znotraj razredaOddelek: Programiranje | 2358 (2028) | phantom |
» | [C++] problem z binarnimi datotekamiOddelek: Programiranje | 952 (817) | mallard |
» | [C++] Insertion sort - problemOddelek: Programiranje | 1108 (947) | Thomas |
» | [C] čuden izpis iz txt dat. na zaslonOddelek: Programiranje | 1675 (1412) | l0g1t3ch |