Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <fstream>
- #include <Windows.h>
- using namespace std;
- void Swap(string* Line, int left, int right)
- {
- string sw = Line[left];
- Line[left] = Line[right];
- Line[right] = sw;
- }
- extern "C" _declspec(dllexport) void Sort(char** arr, int n)
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- //string str = string(arr[0])
- string* Line = new string[n];
- for (int i = 0; i < n; i++) {
- Line[i] = string(arr[i]);
- }
- for (int i = 0; i < n - 1; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- int s = 0; // индекс буквы в слове
- while (true)
- {
- if (Line[i][s] == NULL && Line[j][s] == NULL) break;
- if (Line[i][s] > Line[j][s])
- {
- Swap(Line, i, j);
- break;
- }
- else if (Line[i][s] < Line[j][s]) break;
- s++;
- }
- }
- }
- cout << "\nПосле сортировки:\n";
- for (int i = 0; i < n; i++)
- cout << Line[i] << endl;
- }
Advertisement
RAW Paste Data
Copied
Advertisement