Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Da se podredat iminja po abeceden redosled.
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- char names[20][500];
- int length, temp;
- cout << "Vnesi dolzhina na nizata (max = 20): ";
- cin >> length;
- cout << endl;
- if (length > 20) length = 20;
- temp = length;
- for (int i = 0; i < length; ++i)
- {
- cout << "Vnesi ime: ";
- cin >> names[i];
- }
- do
- {
- int new_length = 0;
- for (int i = 1; i < length; ++i)
- {
- if (strcmp(names[i - 1], names[i]) > 0)
- {
- swap(names[i - 1], names[i]);
- new_length = i;
- }
- }
- length = new_length;
- } while (length != 0);
- for (int i = 0; i < temp; ++i) cout << names[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment