Advertisement
onezee

Untitled

Mar 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. struct Victor {
  9. string* arr;
  10. int maxSize;
  11. int N;
  12.  
  13. Victor(int M) {
  14. maxSize = M;
  15. N = 0;
  16. arr = new string[maxSize];
  17. }
  18.  
  19. void push_back(const string& data) {
  20. if (N == maxSize - 1) {
  21. string* temp = arr;
  22. arr = new string[maxSize += 1];
  23. for (int i = 0; i < N; i++) {
  24. arr[i] = temp[i];
  25. }
  26. delete[] temp;
  27. }
  28. arr[N++] = data;
  29. }
  30.  
  31. void qsort(string* arr, int low, int high) {
  32. int i = low, j = high;
  33. string temp;
  34. string p = arr[(i + j) / 2];
  35.  
  36. while (i <= j) {
  37. while (arr[i].length() < p.length())
  38. i++;
  39. while (arr[j].length() > p.length())
  40. j--;
  41. if (i <= j) {
  42. temp = arr[i];
  43. arr[i] = arr[j];
  44. arr[j] = temp;
  45. i++; j--;
  46. }
  47. }
  48. if (j > low)
  49. qsort(arr, low, j);
  50. if (i < high)
  51. qsort(arr, i, high);
  52.  
  53. }
  54.  
  55. void load(string filename) {
  56. string line;
  57. ifstream in(filename);
  58.  
  59. if (in.is_open()) {
  60. while (getline(in, line))
  61. for (int i = 0; i < line.length(); i++) {
  62. if (line[i] != ".")
  63. }
  64. }
  65. in.close();
  66.  
  67. cout << "Complited" << endl;
  68. }
  69.  
  70. void print() {
  71. for (int i = 0; i < maxSize; i++) {
  72. cout << arr[i] << endl;
  73. }
  74. }
  75. };
  76.  
  77. int main() {
  78. Victor qu(1);
  79. cout << qu.maxSize << endl;
  80. qu.push_back("Hello World!");
  81. cout << qu.maxSize << endl;
  82. qu.push_back("Hello");
  83. cout << qu.maxSize << endl;
  84. qu.push_back("Hello World!x3");
  85. cout << qu.maxSize << endl;
  86. qu.push_back("Hello World!x4");
  87. qu.push_back("Hello World!x5");
  88. qu.print();
  89. qu.qsort(qu.arr, 0, qu.maxSize-1);
  90. qu.print();
  91.  
  92. qu.load("test.txt");
  93.  
  94. _getch();
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement