Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <fstream>
  5. #include <string>
  6. #include <algorithm>
  7. #include <iterator>
  8.  
  9. std::string *tab, *copyTab;
  10. long int n, c;
  11. char k;
  12.  
  13. int *int_tab, *int_copyTab;
  14.  
  15. std::ifstream input;
  16. std::ofstream output;
  17.  
  18. bool isBigger(std::string tab1, std::string tab2);
  19.  
  20. void shellSort_int();
  21.  
  22. int main(){
  23. n = 1;
  24. srand(time(NULL));
  25.  
  26. std::cout << "Ints(1) or Strings(2)?\n";
  27. while (1){
  28. std::cin >> k;
  29. if (k == '1' || k == '2') break;
  30. }
  31.  
  32. if (k == '2'){
  33. std::cout << "\nString chosen. Please choose size: ";
  34. std::cin >> n;
  35. if (n <= 0){
  36. do {
  37. std::cout << "\n Incorrect value. Please insert positive integer ";
  38. std::cin >> n;
  39. } while (n <= 0);
  40. }
  41.  
  42. tab = new std::string[n];
  43. copyTab = new std::string[n];
  44.  
  45. input.open("dic.txt");
  46. for (int j = 0; j < n; j++){
  47. std::getline(input, tab[j]);
  48. }
  49. input.close();
  50. random_shuffle(&tab[0], &tab[n]);
  51. std::copy(tab, tab + n, copyTab);
  52.  
  53. output.open("results.txt");
  54. for (int j = 0; j < n; j++){
  55. output << tab[j] << "\n";
  56. }
  57. output.close();
  58. }
  59.  
  60. else if (k == '1'){
  61. std::cout << "\nInt chosen. Please chose array size: ";
  62. std::cin >> n;
  63. if (n <= 0){
  64. do {
  65. std::cout << "\n Incorrect value. Please insert positive integer ";
  66. std::cin >> n;
  67. } while (n <= 0);
  68. }
  69.  
  70. int_tab = new int[n];
  71. int_copyTab = new int[n];
  72. for (int i = 0; i < n; i++){
  73. int_tab[i] = rand() % 500;
  74. }
  75. std::copy(int_tab, int_tab + n, int_copyTab);
  76.  
  77. shellSort_int();
  78.  
  79. output.open("results.txt");
  80. for (int j = 0; j < n; j++){
  81. output << int_tab[j] << "\n";
  82. }
  83. output.close();
  84. }
  85.  
  86. system("pause");
  87. return 0;
  88.  
  89. }
  90.  
  91.  
  92. bool isBigger(std::string tab1, std::string tab2){
  93. bool isTrue = false;
  94. int len = 0;
  95. if (tab1.length() > tab2.length()) len = tab2.length();
  96. else len = tab1.length();
  97.  
  98. for (int i = 0; i < len; i++){
  99. if (tab1[i] > tab2[i]) {
  100. isTrue = true;
  101. break;
  102. }
  103. else if (tab1[i] < tab2[i]){
  104. isTrue = false;
  105. break;
  106. }
  107. }
  108. return(isTrue);
  109. }
  110.  
  111. void shellSort_int(){
  112. int h = 1;
  113. while (h < n / 9) h = 3 * h + 1;
  114.  
  115. while (h > 0){
  116. for (int i = h ; i < n; i++){
  117. int x = int_tab[i];
  118. int j = i;
  119.  
  120. while ((j >= h) && (x < int_tab[j - h])){
  121. int_tab[j] = int_tab[j - h];
  122. j = j - h;
  123. }
  124. int_tab[j] = x;
  125. }
  126. h /= 3;
  127. }
  128. }
  129.  
  130. void quickSort_int(){
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement