Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- struct Victor {
- string* arr;
- int maxSize;
- int N;
- Victor(int M) {
- maxSize = M;
- N = 0;
- arr = new string[maxSize];
- }
- void push_back(const string& data) {
- if (N == maxSize - 1) {
- string* temp = arr;
- arr = new string[maxSize += 1];
- for (int i = 0; i < N; i++) {
- arr[i] = temp[i];
- }
- delete[] temp;
- }
- arr[N++] = data;
- }
- void qsort(string* arr, int low, int high) {
- int i = low, j = high;
- string temp;
- string p = arr[(i + j) / 2];
- while (i <= j) {
- while (arr[i].length() < p.length())
- i++;
- while (arr[j].length() > p.length())
- j--;
- if (i <= j) {
- temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- i++; j--;
- }
- }
- if (j > low)
- qsort(arr, low, j);
- if (i < high)
- qsort(arr, i, high);
- }
- void load(string filename) {
- string line;
- ifstream in(filename);
- if (in.is_open()) {
- while (getline(in, line))
- for (int i = 0; i < line.length(); i++) {
- if (line[i] != ".")
- }
- }
- in.close();
- cout << "Complited" << endl;
- }
- void print() {
- for (int i = 0; i < maxSize; i++) {
- cout << arr[i] << endl;
- }
- }
- };
- int main() {
- Victor qu(1);
- cout << qu.maxSize << endl;
- qu.push_back("Hello World!");
- cout << qu.maxSize << endl;
- qu.push_back("Hello");
- cout << qu.maxSize << endl;
- qu.push_back("Hello World!x3");
- cout << qu.maxSize << endl;
- qu.push_back("Hello World!x4");
- qu.push_back("Hello World!x5");
- qu.print();
- qu.qsort(qu.arr, 0, qu.maxSize-1);
- qu.print();
- qu.load("test.txt");
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement