Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <conio.h>
- #include <ctime>
- #include <bitset>
- #include <fstream>
- #include <stdlib.h>
- #include <cstring>
- #include <stdexcept>
- #include <random>
- #include <algorithm> //для сортировки
- using namespace std;
- int main()
- {
- setlocale(0, "rus");
- ifstream fin("laba5.txt");
- string buff;
- vector <string> Array;
- int Count = 0; //Kol-vo slov
- cout << "Your words from File:" << endl;
- while (!fin.eof())
- {
- fin >> buff;
- Array.push_back(buff); //Помещаем слова из файла в вектор
- cout << buff << endl;
- Count++;
- }
- string temp; // временная переменная для обмена элементов местами
- // Сортировка массива пузырьком
- for (int i = 0; i < Count; i++) {
- for (int j = 0; j < Array[i].size(); j++) // внутренний цикл
- for (int k = 0; k<Array.size()-j-1;k++)
- {
- if (Array[i][j] > Array[i][j + 1]) // сравниваем два соседних элемента
- {
- // выполняем перестановку элементов массива
- temp[k] = Array[i][j];
- Array[i][j] = Array[i][j + 1];
- Array[i][j + 1] = temp[k];
- }
- }
- }
- cout << endl;
- cout << "Sort:" << endl;
- for (int i = 0; i < Count; i++)
- {
- cout << Array[i] << " ";
- }
- cout << endl;
- fin.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement