Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 48.42 KB | None | 0 0
  1. ///Includes...
  2.  
  3. ///==========================================================================================================
  4.  
  5. #include <iostream> /// pentru cin si cout si namespace ul std
  6. #include <algorithm> /// pentru functia sort
  7. #include <stdio.h> /// pentru printf sau pentru system
  8. #include <stdlib.h> /// pentru system in concordanta cu stdio
  9. #include <cstring> ///pentru strlen, strcmp etc.
  10. #include <windows.h> ///pentru Buffere folosit la clearscreen
  11. #include <vector> ///pentru vectori
  12. #include <complex> ///pentru stringstream convert (C++0x)
  13. #include <typeinfo> /// pentru convert
  14.  
  15. ///==========================================================================================================
  16.  
  17. ///Namespace uri
  18.  
  19. using std::cin;  ///for cin
  20. using std::cout;  ///for cout
  21. using std::sort; ///for sort
  22. using std::vector; ///for vector
  23. using std::string;  ///for string
  24. using std::endl;  ///for endline
  25. using std::istream; ///for istream
  26. using std::ostream; ///for ostream
  27.  
  28. ///==========================================================================================================
  29.  
  30. ///Define uri
  31.  
  32. ///==========================================================================================================
  33.  
  34.  
  35. #define forp(i, n) for(int i=0; i<n; i++) ///scurteaza codul
  36. #define _X dwSize.X
  37. #define _Y dwSize.Y
  38. #define GCSBI GetConsoleScreenBufferInfo
  39. #define FCOC  FillConsoleOutputCharacter
  40. #define FCOA  FillConsoleOutputAttribute
  41. #define SCCP  SetConsoleCursorPosition
  42. #define GSH_S_O_H   GetStdHandle (STD_OUTPUT_HANDLE)
  43.  
  44. ///==========================================================================================================
  45.  
  46. ///Template type verify
  47.  
  48. ///==========================================================================================================
  49.  
  50. template<typename T>
  51. struct is_int
  52. {
  53.     static bool const val = false;
  54.  
  55. };
  56.  
  57. template <>
  58. struct is_int<int>
  59. {
  60.     static bool const val = true;
  61. };
  62.  
  63. template<typename T>
  64. struct is_float
  65. {
  66.     static bool const val = false;
  67.  
  68. };
  69.  
  70. template <>
  71. struct is_float< float >
  72. {
  73.     static bool const val = true;
  74. };
  75.  
  76. template<typename T>
  77. struct is_unsigned_t
  78. {
  79.     static bool const val = false;
  80.  
  81. };
  82.  
  83. template <>
  84. struct is_unsigned_t<unsigned>
  85. {
  86.     static bool const val = true;
  87. };
  88.  
  89. template<typename T>
  90. struct is_vector_string
  91. {
  92.     static bool const val = false;
  93.  
  94. };
  95.  
  96. template <>
  97. struct is_vector_string< vector<string> >
  98. {
  99.     static bool const val = true;
  100. };
  101.  
  102. template<typename T>
  103. struct is_string
  104. {
  105.     static bool const val = false;
  106.  
  107. };
  108.  
  109. template <>
  110. struct is_string< string >
  111. {
  112.     static bool const val = true;
  113. };
  114.  
  115. ///Functions...
  116.  
  117. ///==========================================================================================================
  118.  
  119. void clearscreen()
  120. {
  121.     ///cod preluat de la proiectul numarul 1
  122.     ///stable version of system("cls") ...
  123.     DWORD n;
  124.     COORD coord = {0};
  125.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  126.  
  127.     GCSBI(GSH_S_O_H, &csbi );
  128.     FCOC (GSH_S_O_H, TEXT ( ' ' ), csbi._X * csbi._Y, coord, &n );  ///reseteaza ecranul si duce cursorul la inceput
  129.     GCSBI(GSH_S_O_H, &csbi );
  130.     FCOA (GSH_S_O_H, csbi.wAttributes, csbi._X * csbi._Y, coord, &n );
  131.     SCCP (GSH_S_O_H, coord );
  132. }
  133.  
  134.  
  135. ///Function based on template class T
  136.  
  137. template <class T>
  138. T atoi(const char *s)
  139. {
  140.     ///stable version of atoi(const char *s) ....
  141.     ///complexitatea O(n)
  142.     if(is_unsigned_t<T>::val || is_int<T>::val)
  143.     {
  144.         int ok = 0;
  145.         int len = strlen(s);
  146.         for(int i=0; i < len; i++)
  147.             if (s[i] < '0' || s[i] > '9')
  148.             {
  149.                 if(!(s[i]=='-' && (s[i+1] >= '0' && s[i+1] <= '9')))
  150.                 {
  151.                     ok = 1;;
  152.                     break;
  153.                 }
  154.  
  155.             }
  156.         if (ok == 0)
  157.         {
  158.             T e = 0, *t = new int[len + 1];
  159.             if (s[0] == '-')
  160.             {
  161.                 for (int i=1; i<len; i++)
  162.                 {
  163.                     t[i] = int(s[i] - '0');
  164.                     e=e+t[i];
  165.                     e=e*10;
  166.                 }
  167.                 e = -(e / 10);
  168.                 return e;
  169.             }
  170.  
  171.             else
  172.             {
  173.                 for (int i=0; i<len; i++)
  174.                 {
  175.                     t[i] = int(s[i] - '0');
  176.                     e=e+t[i];
  177.                     e=e*10;
  178.                 }
  179.                 e /= 10;
  180.  
  181.                 return e;
  182.             }
  183.         }
  184.         else
  185.         {
  186.             cout<<"Error 001! It doesn't convert to int because is not a number"<<endl;
  187.             perror(NULL);
  188.             return 9999; ///este pentru nu a aparea warning-uri
  189.         }
  190.     }
  191.     /// ...
  192. }
  193.  
  194. /**template <typename T>
  195. T getline_type(istream &in);
  196.  
  197. template<>
  198. std::string getline_type<std::string>(istream &in){
  199.     string read;
  200.     getline(in, read);
  201.     return read;
  202. }*/
  203.  
  204.  
  205.  
  206. string split (string& s, string remove_t)
  207. {
  208.     size_t pos_start = 0, pos_end, len = remove_t.length();
  209.     string token, combine;
  210.     while ((pos_end = s.find (remove_t, pos_start)) != string::npos)
  211.     {
  212.         token = s.substr (pos_start, pos_end - pos_start);
  213.         pos_start = pos_end + len;
  214.         combine += token;
  215.     }
  216.  
  217.     combine += s.substr(pos_start);
  218.     s = combine;
  219.     return combine;
  220. }
  221.  
  222. bool isNumber(const char* s, char compl1 ='-')
  223. {
  224.     /// Verificare sir de caractere daca formeaza un numar
  225.     int len = strlen(s);
  226.     forp(i, len)
  227.     if (s[i] < '0' || s[i] > '9')
  228.     {
  229.         ///Cazul pt negativ
  230.         if(compl1 == '-')
  231.         {
  232.             if(!(s[i]=='-' && (s[i+1] >= '0' && s[i+1] <= '9')))
  233.                 return false;
  234.         }
  235.         else
  236.             return false;
  237.     }
  238.  
  239.     return true;
  240.     /// ...
  241. }
  242.  
  243. ///==============================================================================================================
  244.  
  245. template <typename T>
  246. T getline_type(istream &in)
  247. {
  248.     string read;
  249.     in>>read;
  250.     T temp;
  251.     if (is_int<T>::val || is_unsigned_t<T>::val || is_float<T>::val) /// EXPERIMENTAL for float types values
  252.     {
  253.         if(!isNumber(read.c_str(), '-'))
  254.             cout<<"Warning 006: You introduced a string type, it will be converted to 0. Bypass!"<<endl;
  255.     }
  256.     if(is_unsigned_t<T>::val)
  257.     {
  258.         char minus_unsigned = read[0];
  259.         if (minus_unsigned == '-')
  260.         {
  261.             cout<<"Warning 005: You introduced a negative number or a bad string. Bypass!"<<endl;
  262.             string unsigned_convert = split(read, "-");
  263.             std::stringstream convert(unsigned_convert);
  264.             convert >> temp;
  265.         }
  266.         else
  267.         {
  268.             std::stringstream convert(read);
  269.             convert >> temp;
  270.         }
  271.         return temp;
  272.     }
  273.  
  274.     std::stringstream convert(read);
  275.     convert >> temp;
  276.     return temp;
  277. }
  278.  
  279. ///=============================================================================================================
  280.  
  281. ///Classess
  282.  
  283. ///1) Class nod
  284.  
  285. ///==========================================================================================================
  286.  
  287. template <class T>
  288. class Nod
  289. {
  290.  
  291. protected:
  292.     T info;
  293.     Nod<T>* next;
  294.  
  295. public:
  296.     Nod<T>()
  297.     {
  298.         next = NULL;
  299.     }
  300.     Nod<T>(T temp)
  301.     {
  302.         info = temp;
  303.         next = NULL;
  304.     }
  305.     void setter(T temp)
  306.     {
  307.         info = temp;
  308.     }
  309.     void setnext(Nod<T> *setnext)
  310.     {
  311.         next = setnext;
  312.     }
  313.     Nod<T>* getnext()
  314.     {
  315.         return next;
  316.     }
  317.     T getdata()
  318.     {
  319.         return info;
  320.     }
  321.     template <class U>
  322.     friend istream& operator>>(istream& in, Nod<U>* nod);
  323.     template <class U>
  324.     friend ostream& operator<<(ostream& out, Nod<U>* nod);
  325. };
  326.  
  327. template <class T>
  328. istream& operator>>(istream& in, Nod<T>* nod)
  329. {
  330.     T info;
  331.     info = getline_type<T>(cin);
  332.     nod->info = info;
  333.     return in;
  334. }
  335.  
  336. template <class T>
  337. ostream& operator<<(ostream& out, Nod<T>* nod)
  338. {
  339.     T info;
  340.     info = nod->info;
  341.     nod->next = nod;
  342.     out<<info;
  343.     return out;
  344. }
  345.  
  346. ///==========================================================================================================
  347.  
  348. ///2) Class Nod_dublu
  349.  
  350. ///==========================================================================================================
  351.  
  352. template <class T>
  353. class Nod_dublu: public Nod<T>
  354. {
  355. protected:
  356.     Nod<T> *ante;  ///nodul anterior
  357.  
  358. public: ///mostenirea
  359.     Nod_dublu<T>():Nod<T>(), ante() { }
  360.     Nod_dublu<T>(T init):Nod<T>(init), ante() { }
  361.     Nod_dublu<T>* convert(Nod<T>* temp)
  362.     {
  363.         Nod_dublu<T>* temp_dublu = new Nod_dublu();
  364.         temp_dublu->setante();
  365.         temp_dublu->setter(temp->getdata());
  366.         temp_dublu->setnext(temp->getnext());
  367.         return temp_dublu;
  368.     }
  369.     Nod<T>* getante()
  370.     {
  371.         return ante;
  372.     }
  373.     void setante(Nod<T>* temp = NULL)
  374.     {
  375.         ante = temp;
  376.     }
  377.     Nod<T>* convert_front(Nod_dublu<T>* temp)
  378.     {
  379.         Nod<T>* gamma = new Nod<T>(temp->getdata());
  380.         T i;
  381.         try
  382.         {
  383.             if(temp == NULL)
  384.             {
  385.                 i = temp->getdata();
  386.                 throw i;
  387.             }
  388.             else
  389.             {
  390.                 gamma->setnext(temp->getnext());
  391.             }
  392.         }
  393.         catch(T i)
  394.         {
  395.             cout<<"Error 002! You tried to convert a double node NULL to a single node"<<endl;
  396.         }
  397.         return gamma;
  398.     }
  399.  
  400.     Nod_dublu<T>* convert_back(Nod<T>* temp)
  401.     {
  402.         T i;
  403.         try
  404.         {
  405.             if(temp == NULL)
  406.             {
  407.                 i = temp->getdata();
  408.                 throw i;
  409.             }
  410.             else
  411.             {
  412.                 this->setter(temp->getdata());
  413.                 this->setnext(temp->getnext());
  414.                 this->setante(NULL);
  415.             }
  416.         }
  417.         catch(T i)
  418.         {
  419.             cout<<"Error 003! You tried to convert a double node NULL to a single node"<<endl;
  420.         }
  421.         return this;
  422.  
  423.     }
  424.  
  425.     template <class U>
  426.     Nod_dublu<U>* operator=(Nod_dublu<U>* temp)
  427.     {
  428.         if(temp->ante == NULL)
  429.             this->ante = NULL;
  430.         if(temp->next == NULL)
  431.         {
  432.             this->ante = temp->ante;
  433.             this->next = NULL;
  434.             this->info = temp->info;
  435.         }
  436.         else
  437.         {
  438.             if(this->ante == NULL && this->info == NULL)
  439.             {
  440.                 perror(ERROR_ACCESS_DENIED);
  441.             }
  442.             else
  443.             {
  444.                 this->ante = temp->ante;
  445.                 this->info = temp->info;
  446.                 this->next = temp->next;
  447.                 return this;
  448.             }
  449.         }
  450.     }
  451.  
  452.     template <class U>
  453.     friend istream& operator>>(istream& in, Nod_dublu<U>* nod);
  454.     template <class U>
  455.     friend ostream& operator<<(ostream& out, Nod_dublu<U>* nod);
  456. };
  457.  
  458.  
  459. template <class T>
  460. istream& operator>>(istream& in, Nod_dublu<T>* nod)
  461. {
  462.     T info;
  463.     info = getline_type<T>(cin);
  464.     nod->info = info;
  465.     return in;
  466. }
  467.  
  468. template <class T>
  469. ostream& operator<<(ostream& out, Nod_dublu<T>* nod)
  470. {
  471.     out<<nod->info;
  472.     return out;
  473. }
  474.  
  475. ///==========================================================================================================
  476.  
  477. ///3) class LDI
  478.  
  479. template <class T>
  480. class LDI
  481. {
  482.     ///Elementele
  483.     Nod_dublu<T>** elemente;
  484.     int elem;
  485.     static int count_sort;
  486. public:
  487.  
  488.     ///Meniu:
  489.     LDI<T>(int cate_elemente = 0)
  490.     {
  491.         elem = cate_elemente;
  492.         elemente = new Nod_dublu<T>*[cate_elemente];
  493.     }
  494.     void reset_space(int cate_elemente)
  495.     {
  496.         elemente = new Nod_dublu<T>*[cate_elemente];
  497.         elem = cate_elemente;
  498.     }
  499.     int space()
  500.     {
  501.         return this->elem;
  502.     }
  503.     Nod_dublu<T>** elemente_return()
  504.     {
  505.         return elemente;
  506.     }
  507.     void push_front(Nod_dublu<T>* head, int i); ///push;
  508.     void push_back(Nod_dublu<T>* back, int i);
  509.     void append(Nod_dublu<T>* append_i, int i);
  510.     void sort_LDI(LDI<T>& obj, bool reverse, bool inserction);
  511.     void sorted(Nod_dublu<T> **cap, Nod_dublu<T> **coada, T key);
  512.     static void get_sorted()
  513.     {
  514.         return count_sort;
  515.     }
  516.     template <class U>
  517.     friend istream& operator>>(istream& in, LDI<U>& ldi);
  518.     template <class U>
  519.     friend ostream& operator<<(ostream& out, LDI<U>& ldi);
  520.     template <class U>
  521.     LDI<U> operator=(LDI<U> ldi)
  522.     {
  523.         this->elem = ldi.elem;
  524.         this->elemente = new Nod_dublu<U>*[ldi.elem];
  525.         for(int i=0; i<elem; i++)
  526.         {
  527.             this->elemente[i] = ldi.elemente[i];
  528.         }
  529.         return *this;
  530.     }
  531.     int size()
  532.     {
  533.         int i=0;
  534.         while(elemente[i]!=NULL)
  535.             i++;
  536.         return i;
  537.     }
  538. };
  539.  
  540. template <class T>
  541. bool compare(Nod_dublu<T>* a, Nod_dublu<T>* b)
  542. {
  543.     return a->getdata() > b->getdata();
  544. }
  545.  
  546. template <class T>
  547. bool compare_front(Nod_dublu<T>* a, Nod_dublu<T>* b)
  548. {
  549.     return a->getdata() < b->getdata();
  550. }
  551.  
  552. template <class T>
  553. void LDI<T>::append(Nod_dublu<T>* append_b, int i)
  554. {
  555.     if (i != elem - 1 && i != 0)
  556.     {
  557.         while(elemente[i]->getante() != NULL)
  558.         {
  559.             Nod_dublu<T>* aux = elemente[i];
  560.             elemente[i] = elemente[i-1];
  561.             elemente[i-1] = aux;
  562.             i--;
  563.         }
  564.     }
  565.     else
  566.     {
  567.         if(i == 0)
  568.         {
  569.             append_b->setante(NULL);
  570.             elemente[i] = append_b;
  571.             return;
  572.         }
  573.  
  574.     }
  575. }
  576.  
  577.  
  578. template <class T>
  579. void LDI<T>::sort_LDI(LDI<T>& obj, bool reverse, bool insertion)
  580. {
  581.     if(insertion == false)
  582.     {
  583.         if(reverse == false)
  584.         {
  585.             sort(obj.elemente, obj.elemente + obj.elem, compare_front<T>);
  586.         }
  587.         else
  588.         {
  589.             sort(obj.elemente, obj.elemente + obj.elem, compare<T>);
  590.         }
  591.  
  592.     }
  593.     else
  594.     {
  595.         LDI<T> sort_t(elem);
  596.         for(int i=0; i<obj.elem; i++)
  597.         {
  598.             T key;
  599.             int j;
  600.             key = obj.elemente[i]->getdata();
  601.             system("pause");
  602.             j = i - 1;
  603.             while(j>=0 && (obj.elemente[j])->getdata() > key)
  604.             {
  605.                 system("pause");
  606.                 obj.elemente[j+1]=obj.elemente[j];
  607.                 j--;
  608.             }
  609.             obj.elemente[j + 1] = new Nod_dublu<T>(key);
  610.             system("pause");
  611.         }
  612.     }
  613.  
  614. }
  615.  
  616. template <class T>
  617. void LDI<T>::push_back(Nod_dublu<T>* back, int i)
  618. {
  619.     try
  620.     {
  621.         if(back == NULL)
  622.             throw i;
  623.     }
  624.     catch(int i)
  625.     {
  626.         cout<<"Error: The double node can't be null"<<endl;
  627.         return;
  628.     }
  629.     Nod_dublu<T>* before = new Nod_dublu<T>();
  630.     before->setter(back->getdata());
  631.     before->setnext(back->getnext());
  632.     if (before->getnext() != NULL)
  633.         before->getante()->setnext(before);
  634.     else
  635.         elemente[i] = before;
  636. }
  637.  
  638. template <class T>
  639. void LDI<T>::push_front(Nod_dublu<T>* head, int i)
  640. {
  641.     LDI<T> temporary(elem+1);
  642.     if(i == elem)
  643.         return;
  644.     else
  645.     {
  646.         temporary.elemente[0] = head;
  647.         int k = 1;
  648.         forp(j, elem)
  649.         {
  650.             temporary.elemente[k] = elemente[j];
  651.             k++;
  652.         }
  653.         elemente = new Nod_dublu<T>*();
  654.         elemente = temporary.elemente;
  655.     }
  656.  
  657. }
  658.  
  659. template <class T>
  660. ostream& operator<<(ostream& out, LDI<T>& ldi)
  661. {
  662.  
  663.     int e = ldi.elem;
  664.     for(int i=0; i<e; i++)
  665.         cout<<(ldi.elemente[i])<<" ";
  666.  
  667.     cout<<endl;
  668.     return out;
  669. }
  670.  
  671. ///==========================================================================================================
  672.  
  673. ///4) Class LSI
  674.  
  675. ///==========================================================================================================
  676.  
  677. template <class T>
  678. class LSI:public LDI<T>
  679. {
  680.     Nod<T>** elemente;
  681. public:
  682.     LSI<T>(int cate_elemente = 0):LDI<T>(cate_elemente) {};
  683.     LSI<T> downgrade(LDI<T> temp)
  684.     {
  685.         int space = temp.space();
  686.         try
  687.         {
  688.             if(space==0)
  689.                 throw space;
  690.             else
  691.             {
  692.                 this->reset_space(space);
  693.                 Nod<T>** elemente_temp = new Nod<T>*[space];
  694.                 Nod_dublu<T>** elemente_temp2 = new Nod_dublu<T>*[space];
  695.                 elemente_temp2 = temp.elemente_return();
  696.                 this->elemente = new Nod<T>*[space];
  697.                 for(int i=0; i<space; i++)
  698.                 {
  699.                     elemente_temp[i] = elemente_temp2[i]->convert_front(elemente_temp2[i]);
  700.                     this->elemente[i] = elemente_temp[i];
  701.                 }
  702.             }
  703.         }
  704.  
  705.         catch(int elem)
  706.         {
  707.             cout<<"Error 001! You tried to convert something null"<<endl;
  708.             perror("Error");
  709.         }
  710.         return *this;
  711.  
  712.     }
  713.     LDI<T> upgrade(LSI<T> temp)
  714.     {
  715.         try
  716.         {
  717.             if(temp.elem==0)
  718.                 throw temp.elem;
  719.             else
  720.             {
  721.                 this->elem = temp.elem;
  722.                 Nod_dublu<T>** elemente_temp = new Nod_dublu<T>*[temp.elem];
  723.                 elemente_temp = convert_back(temp.elemente);
  724.                 this->elemente = elemente_temp;
  725.             }
  726.         }
  727.  
  728.         catch(int elem)
  729.         {
  730.             cout<<"Error 001! You tried to convert something null"<<endl;
  731.             perror("Error");
  732.         }
  733.         return *this;
  734.  
  735.  
  736.     }
  737.     //friend istream& operator>><>(istream& in, LSI<T>&);
  738.     template <class U>
  739.     friend ostream& operator<<(ostream& out, LSI<U>& lsi);
  740. };
  741.  
  742.  
  743. template <class T>
  744. ostream& operator<<(ostream& out, LSI<T>& lsi)
  745. {
  746.     int e = lsi.space();
  747.     for(int i=0; i<e; i++)
  748.         cout<<(lsi.elemente[i])<<" ";
  749.     cout<<endl;
  750.     return out;
  751. }
  752.  
  753. template<typename T>
  754. struct is_LDI
  755. {
  756.     static bool const val = false;
  757.  
  758. };
  759.  
  760. template <class U>
  761. struct is_LDI< LDI<U> >
  762. {
  763.     static bool const val = true;
  764. };
  765.  
  766. template<typename T>
  767. struct is_LSI
  768. {
  769.     static bool const val = false;
  770.  
  771. };
  772.  
  773. template <class U>
  774. struct is_LSI< LSI<U> >
  775. {
  776.     static bool const val = true;
  777. };
  778.  
  779. ///==========================================================================================================
  780.  
  781. ///5) Class count_save
  782.  
  783. ///==========================================================================================================
  784.  
  785. template <class T>
  786. class count_save
  787. {
  788. private:
  789.     vector<T> lista_dubla_finala;
  790.     vector<T> lista_simpla_finala;
  791.  
  792. public:
  793.     int get_vector_size()
  794.     {
  795.         if(is_LDI<T>::val)
  796.             return lista_dubla_finala.size();
  797.         if(is_LSI<T>::val)
  798.             return lista_simpla_finala.size();
  799.         else
  800.         {
  801.             perror("Fail");
  802.         }
  803.     }
  804.     void set_vector(T type);
  805.     void afisare(T type);
  806. };
  807.  
  808. ///==========================================================================================================
  809.  
  810. ///6) Class count_list
  811.  
  812. ///==========================================================================================================
  813.  
  814. class count_list
  815. {
  816. protected:
  817.     static int count_lista_dubla;
  818.     static int count_lista_simpla;
  819.     static int count_all;
  820. public:
  821.     static void set_count(string which, int e);
  822.     static vector <int> get_count();
  823. };
  824.  
  825. int count_list::count_lista_dubla;
  826. int count_list::count_lista_simpla;
  827. int count_list::count_all;
  828.  
  829. vector<int> count_list::get_count()
  830. {
  831.     vector <int> count_list_vec;
  832.     count_list_vec.push_back(count_lista_dubla);
  833.     count_list_vec.push_back(count_lista_simpla);
  834.     count_list_vec.push_back(count_all);
  835.     return count_list_vec;
  836. }
  837.  
  838. void count_list::set_count(string which, int e)
  839. {
  840.  
  841.     if(which == "simpla")
  842.         count_lista_simpla =  e;
  843.  
  844.     if(which == "dubla")
  845.         count_lista_dubla = e;
  846.  
  847.     count_all = count_lista_simpla + count_lista_dubla;
  848. }
  849.  
  850. template <class T>
  851. void count_save<T>::set_vector(T type)
  852. {
  853.     if(is_LDI<T>::val)
  854.     {
  855.         lista_dubla_finala.push_back(type);
  856.     }
  857.     else if(is_LSI<T>::val)
  858.     {
  859.         lista_simpla_finala.push_back(type);
  860.     }
  861.     else
  862.     {
  863.         perror("Fail");
  864.     }
  865.     count_list::set_count("simpla", get_vector_size());
  866. }
  867.  
  868. ///==========================================================================================================
  869.  
  870. ///Menu functions...
  871.  
  872. ///1) LSI_menu
  873.  
  874. ///==========================================================================================================
  875.  
  876. template <class T>
  877. void LSI_meniu()
  878. {
  879.     int n;
  880.     string n_string, string_k;
  881.     do
  882.     {
  883.         cout<<"Cate liste vrei sa citesti?"<<endl;
  884.         cin>>n_string;
  885.         if(!isNumber(n_string.c_str(), '+'))
  886.             cout<<"Warning 007: You inserted a negative number or a string"<<endl;
  887.  
  888.     }
  889.     while(!isNumber(n_string.c_str(), '+'));
  890.     n = atoi<int>(n_string.c_str());
  891.     cout<<"Vei citi urmatoarele "<<n<<" liste"<<endl;
  892.     vector < LSI<T> > lista;
  893.     for(int i=0; i<n; i++)
  894.     {
  895.         cout<<"Lista "<<i<<":"<<endl;
  896.         int k;
  897.         do
  898.         {
  899.             cout<<"Cat spatiu doriti sa alocati?"<<endl;
  900.             cin>>string_k;
  901.             if(!isNumber(string_k.c_str(), '+'))
  902.                 cout<<"Warning 007: You inserted a negative number or a string"<<endl;
  903.         }
  904.         while(!isNumber(string_k.c_str(), '+'));
  905.         k = atoi<int>(string_k.c_str());
  906.         LSI<T> lista_i;
  907.         LDI<T> lista_i_temp;
  908.         if(k==1)
  909.         {
  910.             lista_i.reset_space(k);
  911.             Nod_dublu<T>* nod_d = new Nod_dublu<T>();
  912.             cin>>nod_d;
  913.             lista_i_temp.push_back(nod_d, 0);
  914.         }
  915.         else
  916.         {
  917.             lista_i_temp.reset_space(k);
  918.             for(int j=0; j<k; j++)
  919.             {
  920.                 cout<<"Nodul dublu: "<<j<<endl;
  921.                 Nod_dublu<T>* nod_d = new Nod_dublu<T>();
  922.                 cin>>nod_d;
  923.                 lista_i_temp.push_back(nod_d, j);
  924.             }
  925.             string s;
  926.             cout<<"Doriti sa le sortati? (Yes / No)"<<endl;
  927.             cin>>s;
  928.             if(s == "No")
  929.                 cout<<"Am terminat"<<endl;
  930.             if(s == "Yes")
  931.             {
  932.                 cout<<"Doriti sortarea prin inserctie directa?"<<endl;
  933.                 cout<<"1 - pentru da, 0 - pentru nu"<<endl;
  934.                 string insertion;
  935.                 cin>>insertion;
  936.                 if(insertion == "1")
  937.                     lista_i_temp.sort_LDI(lista_i_temp, false, true);
  938.                 else
  939.                 {
  940.                     cout<<"In ce ordine doriti sa sortati? "<<endl;
  941.                     cout<<"1 - pentru descrescator, 0 - pentru crescator"<<endl;
  942.                     string tru;
  943.                     cin>>tru;
  944.                     if(tru == "1")
  945.                         lista_i_temp.sort_LDI(lista_i_temp, true, false);
  946.                     if(tru == "0")
  947.                         lista_i_temp.sort_LDI(lista_i_temp, false, false);
  948.                 }
  949.                 cout<<"Sortat cu succes"<<endl;
  950.                 cout<<"Am terminat"<<endl;
  951.  
  952.             }
  953.         }
  954.         lista_i=lista_i.downgrade(lista_i_temp);
  955.         lista.push_back(lista_i);
  956.     }
  957.     cout<<"Ai citit asa listele: "<<endl;
  958.     int lista_size = lista.size();
  959.     for(int i=0; i<lista_size; i++)
  960.     {
  961.         cout<<lista[i];
  962.     }
  963.     cout<<"Apasati enter sau asteptati 60 secunde"<<endl;
  964.     system("timeout 60 > nul");
  965. }
  966.  
  967. ///==========================================================================================================
  968.  
  969. ///2) LDI_menu
  970.  
  971. ///==========================================================================================================
  972.  
  973. template <class T>
  974. void LDI_meniu()
  975. {
  976.     int n;
  977.     cout<<"Cate liste vrei sa citesti?"<<endl;
  978.     cin>>n;
  979.     cout<<"Vei citi urmatoarele "<<n<<" liste"<<endl;
  980.     vector < LDI<T> > lista;
  981.     for(int i=0; i<n; i++)
  982.     {
  983.         cout<<"Lista "<<i<<":"<<endl;
  984.         string k_ver;
  985.         int k;
  986.         do
  987.         {
  988.             cout<<"Cat spatiu doriti sa alocati?"<<endl;
  989.             cin>>k_ver;
  990.             if(!isNumber(k_ver.c_str()))
  991.                 cout<<"Warning 001: You inserted a string"<<endl;
  992.         }
  993.         while(!isNumber(k_ver.c_str()));
  994.         k = atoi(k_ver.c_str());
  995.         if(k==1)
  996.         {
  997.             LDI<T> lista_i(1);
  998.             Nod_dublu<T>* nod_d = new Nod_dublu<T>();
  999.             cin>>nod_d;
  1000.             string type_read;
  1001.             do
  1002.             {
  1003.  
  1004.                 cout<<"Doriti sa bagati numarul in fata sau in spate?"<<endl;
  1005.                 cout<<"0 - fata, 1 - spate"<<endl;
  1006.                 cin>>type_read;
  1007.                 if(!isNumber(type_read.c_str()))
  1008.                     cout<<"Warning 001: You inserted a string"<<endl;
  1009.                 else
  1010.                 {
  1011.  
  1012.                     if(atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0)
  1013.                         cout<<"Warining 008: You inserted a bad number"<<endl;
  1014.                 }
  1015.             }
  1016.             while(!isNumber(type_read.c_str()) || atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0);
  1017.             if(type_read == "0")
  1018.                 lista_i.push_front(nod_d,0);
  1019.             else
  1020.             {
  1021.                 lista_i.push_back(nod_d, 0);
  1022.             }
  1023.             lista.push_back(lista_i);
  1024.         }
  1025.         else
  1026.         {
  1027.             LDI<T> lista_i(k);
  1028.             for(int j=0; j<k; j++)
  1029.             {
  1030.                 cout<<"Nodul dublu: "<<j<<endl;
  1031.                 Nod_dublu<T>* nod_d = new Nod_dublu<T>();
  1032.                 cin>>nod_d;
  1033.                 string type_read;
  1034.                 do
  1035.                 {
  1036.  
  1037.                     cout<<"Doriti sa bagati numarul in fata sau in spate?"<<endl;
  1038.                     cout<<"0 - fata, 1 - spate"<<endl;
  1039.                     cin>>type_read;
  1040.                     if(!isNumber(type_read.c_str()))
  1041.                         cout<<"Warning 001: You inserted a string"<<endl;
  1042.                     else
  1043.                     {
  1044.  
  1045.                         if(atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0)
  1046.                             cout<<"Warining 008: You inserted a bad number"<<endl;
  1047.                     }
  1048.                 }
  1049.                 while(!isNumber(type_read.c_str()) || atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0);
  1050.                 if(type_read == "0")
  1051.                     lista_i.push_front(nod_d, j);
  1052.                 else
  1053.                 {
  1054.                     lista_i.push_back(nod_d, j);
  1055.                 }
  1056.             }
  1057.             cout<<"Ai citit:"<<endl;
  1058.             cout<<lista_i<<endl;
  1059.             string s;
  1060.             cout<<"Doriti sa le sortati? (Yes / No)"<<endl;
  1061.             cin>>s;
  1062.             if(s == "No")
  1063.                 cout<<"Am terminat"<<endl;
  1064.             if(s == "Yes")
  1065.             {
  1066.                 cout<<"Doriti sortarea prin inserctie directa?"<<endl;
  1067.                 cout<<"1 - pentru da, 0 - pentru nu"<<endl;
  1068.                 string insertion;
  1069.                 cin>>insertion;
  1070.                 if(insertion == "1")
  1071.                     lista_i.sort_LDI(lista_i, false, true);
  1072.                 else
  1073.                 {
  1074.                     cout<<"In ce ordine doriti sa sortati? "<<endl;
  1075.                     cout<<"1 - pentru descrescator, 0 - pentru crescator"<<endl;
  1076.                     string tru;
  1077.                     cin>>tru;
  1078.                     if(tru == "1")
  1079.                         lista_i.sort_LDI(lista_i, true, false);
  1080.                     if(tru == "0")
  1081.                         lista_i.sort_LDI(lista_i, false, false);
  1082.                 }
  1083.                 cout<<"Sortat cu succes"<<endl;
  1084.                 cout<<"Am terminat"<<endl;
  1085.  
  1086.             }
  1087.             lista.push_back(lista_i);
  1088.         }
  1089.  
  1090.     }
  1091.     ///To clear warning....
  1092.     cout<<"Listele dublu inlantuite sunt: "<<endl;
  1093.     int lista_size = lista.size();
  1094.     for(int i=0; i<lista_size; i++)
  1095.         cout<<lista[i];
  1096.     cout<<"Apasati enter sau asteptati 60 secunde"<<endl;
  1097.     system("timeout 60 > nul");
  1098. }
  1099.  
  1100. ///==========================================================================================================
  1101.  
  1102. ///3) LDI_selected
  1103.  
  1104. ///==========================================================================================================
  1105.  
  1106. template <class T>
  1107. void LDI_selected(string selected)
  1108. {
  1109.     cout<<"Ai selectat lista dubla cu "<<selected<<endl;
  1110.     cout<<"Acum vei citi nodurile in "<<selected<<endl;
  1111.     string k_ver;
  1112.     int k;
  1113.     do
  1114.     {
  1115.         cout<<"Cat spatiu doriti sa alocati?"<<endl;
  1116.         cin>>k_ver;
  1117.         if(!isNumber(k_ver.c_str()))
  1118.             cout<<"Warning 001: You inserted a string"<<endl;
  1119.     }
  1120.     while(!isNumber(k_ver.c_str()));
  1121.     k = atoi(k_ver.c_str());
  1122.     LDI<T> lista(k);
  1123.     for(int i=0; i<k; i++)
  1124.     {
  1125.         cout<<"Nodul "<<i<<" :"<<endl;
  1126.         Nod_dublu<T>* temp = new Nod_dublu<T>();
  1127.         cin>>temp;
  1128.         string type_read;
  1129.         do
  1130.         {
  1131.  
  1132.             cout<<"Doriti sa bagati numarul in fata sau in spate?"<<endl;
  1133.             cout<<"0 - fata, 1 - spate"<<endl;
  1134.             cin>>type_read;
  1135.             if(!isNumber(type_read.c_str()))
  1136.                 cout<<"Warning 001: You inserted a string"<<endl;
  1137.             else
  1138.             {
  1139.  
  1140.                 if(atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0)
  1141.                     cout<<"Warining 008: You inserted a bad number"<<endl;
  1142.             }
  1143.         }
  1144.         while(!isNumber(type_read.c_str()) || atoi<int>(type_read.c_str()) > 1 || atoi<int>(type_read.c_str()) < 0);
  1145.         if(type_read == "0")
  1146.             lista.push_front(temp, i);
  1147.         else
  1148.         {
  1149.             lista.push_back(temp, i);
  1150.         }
  1151.     }
  1152.     string s;
  1153.     cout<<"Doriti sa le sortati? (Yes / No)"<<endl;
  1154.     cin>>s;
  1155.     if(s == "No")
  1156.         cout<<"Am terminat"<<endl;
  1157.     if(s == "Yes")
  1158.     {
  1159.         cout<<"Doriti sortarea prin inserctie directa?"<<endl;
  1160.         cout<<"1 - pentru da, 0 - pentru nu"<<endl;
  1161.         string insertion;
  1162.         cin>>insertion;
  1163.         if(insertion == "1")
  1164.             lista.sort_LDI(lista, false, true);
  1165.         else
  1166.         {
  1167.             cout<<"In ce ordine doriti sa sortati? "<<endl;
  1168.             cout<<"1 - pentru descrescator, 0 - pentru crescator"<<endl;
  1169.             string tru;
  1170.             cin>>tru;
  1171.             if(tru == "1")
  1172.                 lista.sort_LDI(lista, true, false);
  1173.             if(tru == "0")
  1174.                 lista.sort_LDI(lista, false, false);
  1175.         }
  1176.         cout<<"Sortat cu succes"<<endl;
  1177.         cout<<"Am terminat"<<endl;
  1178.  
  1179.     }
  1180.     count_save < LDI <T> > obj;
  1181.     obj.set_vector(lista);
  1182.     return;
  1183. }
  1184.  
  1185. ///==========================================================================================================
  1186.  
  1187. ///4) LSI_selected
  1188.  
  1189. ///==========================================================================================================
  1190.  
  1191. template <class T>
  1192. void LSI_selected(string selected)
  1193. {
  1194.     cout<<"Ai selectat lista dubla cu "<<selected<<endl;
  1195.     cout<<"Acum vei citi nodurile in "<<selected<<endl;
  1196.     string k_ver;
  1197.     int k;
  1198.     do
  1199.     {
  1200.         cout<<"Cat spatiu doriti sa alocati?"<<endl;
  1201.         cin>>k_ver;
  1202.         if(!isNumber(k_ver.c_str()))
  1203.             cout<<"Warning 001: You inserted a string"<<endl;
  1204.     }
  1205.     while(!isNumber(k_ver.c_str()));
  1206.     k = atoi<int>(k_ver.c_str());
  1207.     LDI<T> lista(k);
  1208.     LSI<T> lista_convert(k);
  1209.     for(int i=0; i<k; i++)
  1210.     {
  1211.         cout<<"Nodul "<<i<<" :"<<endl;
  1212.         Nod_dublu<T>* temp = new Nod_dublu<T>();
  1213.         cin>>temp;
  1214.         lista.push_back(temp, i);
  1215.     }
  1216.     string s;
  1217.     cout<<"Doriti sa le sortati? (Yes / No)"<<endl;
  1218.     cin>>s;
  1219.     if(s == "No")
  1220.         cout<<"Am terminat"<<endl;
  1221.     if(s == "Yes")
  1222.     {
  1223.         cout<<"Doriti sortarea prin inserctie directa?"<<endl;
  1224.         cout<<"1 - pentru da, 0 - pentru nu"<<endl;
  1225.         string insertion;
  1226.         cin>>insertion;
  1227.         if(insertion == "1")
  1228.             lista.sort_LDI(lista, false, true);
  1229.         else
  1230.         {
  1231.             cout<<"In ce ordine doriti sa sortati? "<<endl;
  1232.             cout<<"1 - pentru descrescator, 0 - pentru crescator"<<endl;
  1233.             string tru;
  1234.             cin>>tru;
  1235.             if(tru == "1")
  1236.                 lista.sort_LDI(lista, true, false);
  1237.             if(tru == "0")
  1238.                 lista.sort_LDI(lista, false, false);
  1239.         }
  1240.         cout<<"Sortat cu succes"<<endl;
  1241.         cout<<"Am terminat"<<endl;
  1242.     }
  1243.     system("pause");
  1244.     lista_convert.downgrade(lista);
  1245.     cout<<lista_convert<<endl;
  1246.     system("pause");
  1247.     count_save< LSI<T> >obj1;
  1248.     obj1.set_vector(lista_convert);
  1249.     return;
  1250. }
  1251.  
  1252. ///==========================================================================================================
  1253.  
  1254.  
  1255. ///5) combinations LDI
  1256.  
  1257.  
  1258. ///==========================================================================================================
  1259.  
  1260. void combinatie_tipuri_lista_dubla()
  1261. {
  1262.     cout<<"Ai selectat combinatie lista dubla"<<endl;
  1263.     vector < LDI <string > > trick_complet;
  1264.     string count_t;
  1265.     do
  1266.     {
  1267.         cout<<"Cate liste de combinatii doresti sa citesti?"<<endl;
  1268.         cin>>count_t;
  1269.         if(!isNumber(count_t.c_str(), 'a'))
  1270.             cout<<"Warning 007: You introduced a bad number or a string. Bypass!"<<endl;
  1271.     }
  1272.     while(!isNumber(count_t.c_str(), 'a'));
  1273.     int n = atoi(count_t.c_str());
  1274.     forp(i, n)
  1275.     {
  1276.         LDI <string> trick; ///The trick is that a string supports every type of values (it's so powerful)
  1277.         string j_string;
  1278.         do
  1279.         {
  1280.             cout<<"Cat spatiu doriti sa alocati per lista?"<<endl;
  1281.             cin>>j_string;
  1282.             if(!isNumber(j_string.c_str(), 'a'))
  1283.                 cout<<"Warning 007: You introduced a bad number or a string. Bypass!"<<endl;
  1284.         }
  1285.         while(!isNumber(j_string.c_str(), 'a'));
  1286.         int k = atoi<int>(j_string.c_str());
  1287.         forp(j, k)
  1288.         {
  1289.             string in;
  1290.             cout<<"Introduceti un tip de variabila din lista de mai jos"<<endl;
  1291.             cout<<"String, Float, Int, Unsigned si Char sau Exit pentru a iesi"<<endl;
  1292.             cin>>in;
  1293.             string node;
  1294.             if(in == "String") ///Basically is the same, no problems ....
  1295.             {
  1296.                 cin>>node;
  1297.                 cout<<"Nod creat"<<endl;
  1298.             }
  1299.             if(in == "Float") ///We have some problems here
  1300.             {
  1301.                 cin>>node; ///Didn't create a number verify
  1302.                 cout<<"Nod creat"<<endl;
  1303.             }
  1304.             if(in == "Int") ///We have some problems here
  1305.             {
  1306.                 do
  1307.                 {
  1308.                     cin>>node;
  1309.                     if(!isNumber(node.c_str(), '-'))
  1310.                         cout<<"Warning 006: You inserted a string"<<endl;
  1311.                 }
  1312.                 while(!isNumber(node.c_str(), '-'));
  1313.                 cout<<"Nod creat"<<endl;
  1314.             }
  1315.             if(in == "Unsigned")
  1316.             {
  1317.                 do
  1318.                 {
  1319.                     cin>>node;
  1320.                     if(!isNumber(node.c_str(), '+'))
  1321.                         cout<<"Warning 006: You inserted a string or a negative number"<<endl;
  1322.                 }
  1323.                 while(!isNumber(node.c_str(), '+'));
  1324.                 cout<<"Nod creat"<<endl;
  1325.             }
  1326.             if(in == "Char") ///We don't have problems because a string is the same like vector <char> so it's fine
  1327.             {
  1328.                 do
  1329.                 {
  1330.                     cin>>node;
  1331.                     if(node.length() > 2 || node.length() < 0)
  1332.                     {
  1333.                         cout<<"You inserted a string characted not a char"<<endl;
  1334.  
  1335.                     }
  1336.                 }
  1337.                 while(node.length() > 2 || node.length() < 0);
  1338.                 cout<<"Nod creat"<<endl;
  1339.             }
  1340.             Nod_dublu<string>* node_string  = new Nod_dublu<string>(node);
  1341.             trick.push_back(node_string, j);
  1342.             if(in == "Exit")
  1343.                 break;
  1344.         }
  1345.         cout<<"Doriti sa sortati?"<<endl;
  1346.         cout<<"Yes pentru da, orice altceva pentru nu"<<endl;
  1347.         string gamma;
  1348.         cin>>gamma;
  1349.         if(gamma == "Yes")
  1350.         {
  1351.             string test;
  1352.             cout<<"Doriti sa fie sortarea prin inserctie sau simpla (0 - nu / 1 - da)?"<<endl;
  1353.             do
  1354.             {
  1355.                 cin>>test;
  1356.                 if(!isNumber(test.c_str()) || atoi(test.c_str()) > 1 || atoi(test.c_str()) < 0)
  1357.                     cout<<"Warning 007: You inserted a string or a bad number! Bypass..."<<endl;
  1358.             }
  1359.             while (!isNumber(test.c_str()) || atoi(test.c_str()) > 1 || atoi(test.c_str()) < 0);
  1360.             if(test == "0")
  1361.             {
  1362.  
  1363.                 cout<<"Sortarea se face prin qsort"<<endl;
  1364.                 cout<<"Doriti sa fie reverse sau nu? (Yes - pentru da, orice altceva pt nu)"<<endl;
  1365.                 string yes;
  1366.                 cin>>yes;
  1367.                 if(yes=="Yes")
  1368.                 {
  1369.                     trick.sort_LDI(trick, true, false);
  1370.                 }
  1371.                 else
  1372.                 {
  1373.                     trick.sort_LDI(trick, false, false);
  1374.                 }
  1375.             }
  1376.             else
  1377.             {
  1378.                 trick.sort_LDI(trick, false, true);
  1379.             }
  1380.             cout<<"Sortat cu succes"<<endl;
  1381.             cout<<"Am terminat"<<endl;
  1382.         }
  1383.         else
  1384.         {
  1385.             cout<<"Ai selectat sa nu sortezi"<<endl;
  1386.             cout<<"Am terminat"<<endl;
  1387.         }
  1388.         trick_complet.push_back(trick);
  1389.     }
  1390.     int space = trick_complet.size(); /// to escape the warning
  1391.     for(int i=0; i<space; i++)
  1392.     {
  1393.         cout<<trick_complet[i];
  1394.     }
  1395.     cout<<"Ai 30 de secunde la dispoztie sau apasa enter"<<endl;
  1396.     system("timeout 30 > null");
  1397. }
  1398.  
  1399. ///==========================================================================================================
  1400.  
  1401.  
  1402. ///6) combinations LSI
  1403.  
  1404.  
  1405. ///==========================================================================================================
  1406.  
  1407. void combinatie_tipuri_lista_simpla()
  1408. {
  1409.     cout<<"Ai selectat combinatie lista dubla"<<endl;
  1410.     vector < LSI <string > > trick_complet;
  1411.     string count_t;
  1412.     do
  1413.     {
  1414.         cout<<"Cate liste de combinatii doresti sa citesti?"<<endl;
  1415.         cin>>count_t;
  1416.         if(!isNumber(count_t.c_str(), 'a'))
  1417.             cout<<"Warning 007: You introduced a bad number or a string. Bypass!"<<endl;
  1418.     }
  1419.     while(!isNumber(count_t.c_str(), 'a'));
  1420.     int n = atoi(count_t.c_str());
  1421.     forp(i, n)
  1422.     {
  1423.         LDI <string> trick; ///The trick is that a string supports every type of values (it's so powerful)
  1424.         string j_string;
  1425.         do
  1426.         {
  1427.             cout<<"Cat spatiu doriti sa alocati per lista?"<<endl;
  1428.             cin>>j_string;
  1429.             if(!isNumber(j_string.c_str(), 'a'))
  1430.                 cout<<"Warning 007: You introduced a bad number or a string. Bypass!"<<endl;
  1431.         }
  1432.         while(!isNumber(j_string.c_str(), 'a'));
  1433.         int k = atoi<int>(j_string.c_str());
  1434.         forp(j, k)
  1435.         {
  1436.             string in;
  1437.             cout<<"Introduceti un tip de variabila din lista de mai jos"<<endl;
  1438.             cout<<"String, Float, Int, Unsigned si Char sau Exit pentru a iesi"<<endl;
  1439.             cin>>in;
  1440.             string node;
  1441.             if(in == "String") ///Basically is the same, no problems ....
  1442.             {
  1443.                 cin>>node;
  1444.                 cout<<"Nod creat"<<endl;
  1445.             }
  1446.             if(in == "Float") ///We have some problems here
  1447.             {
  1448.                 cin>>node; ///Didn't create a number verify
  1449.                 cout<<"Nod creat"<<endl;
  1450.             }
  1451.             if(in == "Int") ///We have some problems here
  1452.             {
  1453.                 do
  1454.                 {
  1455.                     cin>>node;
  1456.                     if(!isNumber(node.c_str(), '-'))
  1457.                         cout<<"Warning 006: You inserted a string"<<endl;
  1458.                 }
  1459.                 while(!isNumber(node.c_str(), '-'));
  1460.                 cout<<"Nod creat"<<endl;
  1461.             }
  1462.             if(in == "Unsigned")
  1463.             {
  1464.                 do
  1465.                 {
  1466.                     cin>>node;
  1467.                     if(!isNumber(node.c_str(), '+'))
  1468.                         cout<<"Warning 006: You inserted a string or a negative number"<<endl;
  1469.                 }
  1470.                 while(!isNumber(node.c_str(), '+'));
  1471.                 cout<<"Nod creat"<<endl;
  1472.             }
  1473.             if(in == "Char") ///We don't have problems because a string is the same like vector <char> so it's fine
  1474.             {
  1475.                 do
  1476.                 {
  1477.                     cin>>node;
  1478.                     if(node.length() > 2 || node.length() < 0)
  1479.                     {
  1480.                         cout<<"You inserted a string characted not a char"<<endl;
  1481.  
  1482.                     }
  1483.                 }
  1484.                 while(node.length() > 2 || node.length() < 0);
  1485.                 cout<<"Nod creat"<<endl;
  1486.             }
  1487.             Nod_dublu<string>* node_string  = new Nod_dublu<string>(node);
  1488.             trick.push_back(node_string, j);
  1489.             if(in == "Exit")
  1490.                 break;
  1491.         }
  1492.         cout<<"Doriti sa sortati?"<<endl;
  1493.         cout<<"Yes pentru da, orice altceva pentru nu"<<endl;
  1494.         string gamma;
  1495.         cin>>gamma;
  1496.         if(gamma == "Yes")
  1497.         {
  1498.             string test;
  1499.             cout<<"Doriti sa fie sortarea prin inserctie sau simpla (0 - nu / 1 - da)?"<<endl;
  1500.             do
  1501.             {
  1502.                 cin>>test;
  1503.                 if(!isNumber(test.c_str()) || atoi(test.c_str()) > 1 || atoi(test.c_str()) < 0)
  1504.                     cout<<"Warning 007: You inserted a string or a bad number! Bypass..."<<endl;
  1505.             }
  1506.             while (!isNumber(test.c_str()) || atoi(test.c_str()) > 1 || atoi(test.c_str()) < 0);
  1507.             if(test == "0")
  1508.             {
  1509.  
  1510.                 cout<<"Sortarea se face prin qsort"<<endl;
  1511.                 cout<<"Doriti sa fie reverse sau nu? (Yes - pentru da, orice altceva pt nu)"<<endl;
  1512.                 string yes;
  1513.                 cin>>yes;
  1514.                 if(yes=="Yes")
  1515.                 {
  1516.                     trick.sort_LDI(trick, true, false);
  1517.                 }
  1518.                 else
  1519.                 {
  1520.                     trick.sort_LDI(trick, false, false);
  1521.                 }
  1522.             }
  1523.             else
  1524.             {
  1525.                 trick.sort_LDI(trick, false, true);
  1526.             }
  1527.             cout<<"Sortat cu succes"<<endl;
  1528.             cout<<"Am terminat"<<endl;
  1529.         }
  1530.         else
  1531.         {
  1532.             cout<<"Ai selectat sa nu sortezi"<<endl;
  1533.             cout<<"Am terminat"<<endl;
  1534.         }
  1535.         LSI<string> var;
  1536.         trick_complet.push_back(var.downgrade(trick));
  1537.     }
  1538.     int space = trick_complet.size(); /// to escape the warning
  1539.     for(int i=0; i<space; i++)
  1540.     {
  1541.         cout<<trick_complet[i];
  1542.     }
  1543.     cout<<"Ai 30 de secunde la dispoztie sau apasa enter"<<endl;
  1544.     system("timeout 30 > null");
  1545. }
  1546.  
  1547. ///==========================================================================================================
  1548.  
  1549. ///7) LSD_LDI based on 5 and 6
  1550.  
  1551. ///==========================================================================================================
  1552.  
  1553. void LSI_LDI()
  1554. {
  1555.     string s;
  1556.     while(true)
  1557.     {
  1558.         clearscreen();
  1559.         cout<<"Ai select lista dublu inlantuite sau simplu inlantuie. Selecteaza una dintre varinate apoi tipul listei"<<endl;
  1560.         cout<<"1) Int"<<endl;
  1561.         cout<<"2) Unsigned"<<endl;
  1562.         cout<<"3) Char"<<endl;
  1563.         cout<<"4) String"<<endl;
  1564.         cout<<"5) Float"<<endl;
  1565.         cout<<"6) Combinatie (EXPERIMENTAL)"<<endl;
  1566.         cout<<"7) Back"<<endl;
  1567.         cout<<"8) Detalii liste citite / afisare"<<endl;
  1568.         cin>>s;
  1569.         if(s == "8")
  1570.         {
  1571.             clearscreen();
  1572.             cout<<"Detalii despre listele citite sunt:"<<endl;
  1573.             vector <int> temp = count_list::get_count();
  1574.             cout<<"Numarul de liste dublu inlantuite:"<<endl;
  1575.             cout<<temp[0]<<endl;
  1576.             cout<<"Numarul de liste simplu inlantuite:"<<endl;
  1577.             cout<<temp[1]<<endl;
  1578.             cout<<"Numarul de liste in total:"<<endl;
  1579.             cout<<temp[2]<<endl;
  1580.             cout<<"Ai 30 de secunde sa te uiti"<<endl;
  1581.             system("timeout 30 > nul");
  1582.         }
  1583.         else
  1584.         {
  1585.             clearscreen();
  1586.             string tip;
  1587.             cout<<"Selecteaza tipul listei (0 - lista_dubla) (1 - lista simpla)"<<endl;
  1588.             cin>>tip;
  1589.             if(tip == "1")
  1590.             {
  1591.                 if(s == "1")
  1592.                     LSI_selected<int>("Int");
  1593.                 if(s == "2")
  1594.                     LSI_selected<unsigned>("Unsigned");
  1595.                 if(s == "3")
  1596.                     LSI_selected<char>("Char");
  1597.                 if(s == "4")
  1598.                     LSI_selected<string>("String");
  1599.                 if(s == "5")
  1600.                     LSI_selected<float>("Float");
  1601.                 if(s == "6")
  1602.                     cout<<"In constructie"<<endl;
  1603.                 if(s == "7")
  1604.                     break;
  1605.             }
  1606.             if(tip == "0")
  1607.             {
  1608.                 if(s == "1")
  1609.                     LDI_selected<int>("Int");
  1610.                 if(s == "2")
  1611.                     LDI_selected<unsigned>("Unsigned");
  1612.                 if(s == "3")
  1613.                     LDI_selected<char>("Char");
  1614.                 if(s == "4")
  1615.                     LDI_selected<string>("String");
  1616.                 if(s == "5")
  1617.                     LDI_selected<float>("Float");
  1618.                 if(s == "6")
  1619.                     cout<<"In constructie"<<endl;
  1620.                 if(s == "7")
  1621.                     break;
  1622.             }
  1623.         }
  1624.     }
  1625. }
  1626.  
  1627. ///==========================================================================================================
  1628.  
  1629. /// The main of the program
  1630.  
  1631. ///==========================================================================================================
  1632.  
  1633. int main()
  1634. {
  1635.  
  1636.     int n;
  1637.     while(true)
  1638.     {
  1639.         printf("Bun venit la meniu! Realizat de Mihalea Andreas, tema 1! '60%' din program realizat ('70%' din tema)\n"); ///To optimise the code
  1640.         printf("Selectati:\n");
  1641.         printf("1) Liste dublu inlantuite\n");
  1642.         printf("2) Liste simplu inlantuite\n");
  1643.         printf("3) Combinatii liste simplu / dublu inlantuie\n");
  1644.         printf("4) Exit\n");
  1645.         scanf("%d", &n);
  1646.         if(n == 1)
  1647.         {
  1648.             clearscreen();
  1649.             printf("Ai select lista dublu inlantuite\n");
  1650.             printf("1) Int\n");
  1651.             printf("2) Unsigned\n");
  1652.             printf("3) Char\n");
  1653.             printf("4) String\n");
  1654.             printf("5) Float\n");
  1655.             printf("6) Combinatie (EXPERIMENTAL)\n");
  1656.             printf("7) Back\n");
  1657.             int k;
  1658.             scanf("%d", &k);
  1659.             if(k == 1)
  1660.                 LDI_meniu<int>();
  1661.             if(k == 2)
  1662.                 LDI_meniu<unsigned>();
  1663.             if(k == 3)
  1664.                 LDI_meniu<char>();
  1665.             if(k == 4)
  1666.                 LDI_meniu<string>();
  1667.             if(k == 5)
  1668.                 LDI_meniu<float>();
  1669.             if(k == 7)
  1670.             {
  1671.                 clearscreen();
  1672.                 continue;
  1673.             }
  1674.             if(k == 6)
  1675.             {
  1676.                 clearscreen();
  1677.                 combinatie_tipuri_lista_dubla();
  1678.             }
  1679.         }
  1680.         if(n == 2)
  1681.         {
  1682.             clearscreen();
  1683.             printf("Ai select lista simplu inlantuite\n");
  1684.             printf("1) Int\n");
  1685.             printf("2) Unsigned\n");
  1686.             printf("3) Char\n");
  1687.             printf("4) String\n");
  1688.             printf("5) Float\n");
  1689.             printf("6) Combinatie (EXPERIMENTAL)\n");
  1690.             printf("7) Back\n");
  1691.             int k;
  1692.             cin>>k;
  1693.             if(k == 1)
  1694.                 LSI_meniu<int>();
  1695.             if(k == 1)
  1696.                 LSI_meniu<int>();
  1697.             if(k == 2)
  1698.                 LSI_meniu<unsigned>();
  1699.             if(k == 3)
  1700.                 LSI_meniu<char>();
  1701.             if(k == 4)
  1702.                 LSI_meniu<string>();
  1703.             if(k == 5)
  1704.                 LSI_meniu<float>();
  1705.             if(k == 7)
  1706.             {
  1707.                 clearscreen();
  1708.                 continue;
  1709.             }
  1710.             if(k == 6)
  1711.             {
  1712.                 clearscreen();
  1713.                 combinatie_tipuri_lista_simpla();
  1714.             }
  1715.         }
  1716.         if(n == 3)
  1717.         {
  1718.             clearscreen();
  1719.             LSI_LDI();
  1720.         }
  1721.         if(n == 4)
  1722.         {
  1723.             clearscreen();
  1724.             printf("Ai iesit din program\n");
  1725.             return 0;
  1726.         }
  1727.     }
  1728. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement