Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- #include <fstream>
- #include <string>
- #include <algorithm>
- #include <iterator>
- std::string *tab, *copyTab;
- long int n, c;
- char k;
- int *int_tab, *int_copyTab;
- std::ifstream input;
- std::ofstream output;
- bool isBigger(std::string tab1, std::string tab2);
- void shellSort_int();
- int main(){
- n = 1;
- srand(time(NULL));
- std::cout << "Ints(1) or Strings(2)?\n";
- while (1){
- std::cin >> k;
- if (k == '1' || k == '2') break;
- }
- if (k == '2'){
- std::cout << "\nString chosen. Please choose size: ";
- std::cin >> n;
- if (n <= 0){
- do {
- std::cout << "\n Incorrect value. Please insert positive integer ";
- std::cin >> n;
- } while (n <= 0);
- }
- tab = new std::string[n];
- copyTab = new std::string[n];
- input.open("dic.txt");
- for (int j = 0; j < n; j++){
- std::getline(input, tab[j]);
- }
- input.close();
- random_shuffle(&tab[0], &tab[n]);
- std::copy(tab, tab + n, copyTab);
- output.open("results.txt");
- for (int j = 0; j < n; j++){
- output << tab[j] << "\n";
- }
- output.close();
- }
- else if (k == '1'){
- std::cout << "\nInt chosen. Please chose array size: ";
- std::cin >> n;
- if (n <= 0){
- do {
- std::cout << "\n Incorrect value. Please insert positive integer ";
- std::cin >> n;
- } while (n <= 0);
- }
- int_tab = new int[n];
- int_copyTab = new int[n];
- for (int i = 0; i < n; i++){
- int_tab[i] = rand() % 500;
- }
- std::copy(int_tab, int_tab + n, int_copyTab);
- shellSort_int();
- output.open("results.txt");
- for (int j = 0; j < n; j++){
- output << int_tab[j] << "\n";
- }
- output.close();
- }
- system("pause");
- return 0;
- }
- bool isBigger(std::string tab1, std::string tab2){
- bool isTrue = false;
- int len = 0;
- if (tab1.length() > tab2.length()) len = tab2.length();
- else len = tab1.length();
- for (int i = 0; i < len; i++){
- if (tab1[i] > tab2[i]) {
- isTrue = true;
- break;
- }
- else if (tab1[i] < tab2[i]){
- isTrue = false;
- break;
- }
- }
- return(isTrue);
- }
- void shellSort_int(){
- int h = 1;
- while (h < n / 9) h = 3 * h + 1;
- while (h > 0){
- for (int i = h ; i < n; i++){
- int x = int_tab[i];
- int j = i;
- while ((j >= h) && (x < int_tab[j - h])){
- int_tab[j] = int_tab[j - h];
- j = j - h;
- }
- int_tab[j] = x;
- }
- h /= 3;
- }
- }
- void quickSort_int(){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement