Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <random>
- #include <algorithm>
- #include <math.h>
- #include <string>
- #include <sstream>
- using namespace std;
- void Print(string* b, int size) {
- for (int i = 0; i < size; i++) {
- cout << b[i] << endl;
- }
- }
- void BubleSort(string* b, int size) {
- string temp; // временная переменная для обмена элементов местами
- // Сортировка массива пузырьком
- for (int i = 0; i < size - 1; i++) {
- for (int j = 0; j < size - i - 1; j++) {
- if (b[j].length() > b[j + 1].length()) {
- // меняем элементы местами
- temp = b[j];
- b[j] = b[j + 1];
- b[j + 1] = temp;
- }
- }
- }
- }
- int main() {
- const int size = 10;
- string b[size] = { "qwe", "q", "ty", "erv", "dffg", "eqwerwe", "q", "dsfd", "wer", "dsfsdf"};
- Print(b, size);
- BubleSort(b, size);
- cout << endl;
- Print(b, size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment