Advertisement
dllbridge

Untitled

Oct 29th, 2023
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.62 KB | None | 0 0
  1.  
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6.  
  7. template<typename T>
  8. T  foo(T  t);
  9.  
  10.  
  11.  
  12.  
  13. /////////////////////////////////////////////////////
  14. int main()
  15. {
  16.  
  17.     cout << foo(3) << " - " << foo(3.0) << endl;
  18.  
  19. }
  20.  
  21.  
  22. template<typename T>
  23. /////////////////////////////////////////////////////
  24. T  foo(T  t)
  25. {
  26.    
  27.    
  28. return t/2;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. /*
  46.  
  47. #include <iostream>
  48. using namespace std;
  49.  
  50.  
  51.  
  52. int    foo(int   n);
  53. double foo(double n);
  54.  
  55.  
  56.  
  57. /////////////////////////////////////////////////////
  58. int main()
  59. {
  60.  
  61.     cout << foo(3) << " - " << foo(3.0) << endl;
  62.  
  63. }
  64.  
  65.  
  66.  
  67. /////////////////////////////////////////////////////
  68. int foo(int   n)
  69. {
  70.    
  71.    
  72. return n/2;
  73. }
  74.  
  75.  
  76.  
  77. /////////////////////////////////////////////////////
  78. double foo(double f)                                 //
  79. {
  80.    
  81. return f/2;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88. */
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. /*
  113. #include <stdio.h>
  114.  
  115.  
  116.  
  117. void foo(int n);
  118.  
  119. /////////////////////////////////////////////////////
  120. int main()
  121. {
  122.  
  123.     int n = 100;
  124.    
  125.     foo(n);
  126.  
  127.     printf("n from matn = %d\n", n);
  128. }
  129.  
  130.  
  131. //////////////////////////////////////////////////////
  132. void foo(int n)
  133. {
  134.    
  135.      n = n - 77;
  136. }
  137.  
  138.  
  139.  
  140.  
  141. */
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. /*
  157. #include <iostream>
  158. #include    <queue>
  159.  
  160. using namespace std;
  161.  
  162.  
  163. //////////////////////////////////////////////////////////////////////
  164. int main()
  165. {
  166.  
  167.  
  168.   queue<string> animals;                             // create a queue of string
  169.  
  170.  
  171.   animals.push("Cat");                           // push elements into the queue
  172.   animals.push("Dog");
  173.  
  174.   cout << "Queue: ";
  175.  
  176.  
  177.    
  178.  
  179.  
  180.   while(animals.empty() != 1)   // print elements of queue loop until queue is empty
  181.   {
  182.                                          
  183.     cout << animals.front() << ", ";                         // print the element
  184.  
  185.     animals.pop();                                 // pop element from the queue
  186.  
  187.   }
  188.  
  189.   cout << endl;
  190.  
  191.   return 0;
  192. }
  193. */
  194.  
  195.  
  196.  
  197.  
  198.  
  199. /*
  200.  
  201. #include <iostream>
  202. #include    <queue>
  203. using namespace std;
  204.  
  205.  
  206. void display_queue(queue<string> q);               // function prototype for display_queue utility
  207. /////////////////////////////////////////////////////
  208. int main()
  209. {
  210.  
  211.  
  212.   queue<string> animals;                           // create a queue of string
  213.  
  214.  
  215.   animals.push("Cat");                             // push element into the queue
  216.   animals.push("Dog");
  217.   animals.push("Fox");
  218.  
  219.   cout << "Initial Queue: ";
  220.   display_queue(animals);
  221.  
  222.  
  223.   animals.pop();                                   // remove element from queue
  224.  
  225.   cout << "Final Queue: ";
  226.   display_queue(animals);
  227.  
  228.   return 0;
  229. }
  230.  
  231.  
  232.  
  233. ///////////////////////////////////////////////// utility function to display queue
  234. void display_queue(queue<string> q)
  235. {
  236.    
  237.    while(q.empty() != 1)
  238.    {
  239.       cout << q.front() << ", ";
  240.       q.pop();
  241.    }
  242.  
  243.   cout << endl;
  244. }
  245. */
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259. /*
  260.  
  261. #include  <iostream>                                      //                      push()
  262. #include     <queue>                                      //                     front()
  263. using namespace std;                                      //                      back()  
  264.  
  265.  
  266. ////////////////////////////////////////////////////////////
  267. int main()                                                //
  268. {
  269.  
  270.   queue<int> nums;                                        //       create a queue of int
  271.  
  272.   for(int i = 0; i < 97; i++)
  273.   {
  274.        
  275.       nums.push(i+10);  
  276.   }
  277.  
  278.  //                                                            // push element into the queue
  279.  // nums.push(2);
  280.  // nums.push(3);
  281.  
  282.   int front = nums.front();                               // get the element at the front
  283.   int back  = nums.back ();                                 //  get the element at the back  
  284.   cout << "First element: " << front << endl;
  285.   cout << "Last  element: " << back  << endl;
  286.  
  287.  
  288.  
  289. return 0;
  290. }
  291.  
  292.  
  293.  
  294. */
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316. /*
  317.  
  318.  
  319. #include  <iostream>                                      //                      push()
  320. #include     <queue>                                      //                      size()
  321. using namespace std;
  322.  
  323. ////////////////////////////////////////////////////////////
  324. int main()                                                //
  325. {
  326.  
  327.   queue<string> languages;                                //    create a queue of string
  328.  
  329.   languages.push("Python");                               // push element into the queue
  330.   languages.push("C++"   );
  331.   languages.push("Java"  );
  332.  
  333.   int size = languages.size();                            //   get the size of the queue
  334.   cout << "Size of the queue: " << size;
  335.  
  336. return 0;
  337. }
  338.  
  339.  
  340.  
  341.  
  342.  
  343. */
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. /*
  359. #include  <iostream>
  360. #include     <queue>
  361. using namespace std;
  362.  
  363. ////////////////////////////////////////////////////////////
  364. int main()
  365. {
  366.  
  367.  
  368.   queue<string> languages;                                // create a queue of string
  369.  
  370.   cout << "Is the queue empty? ";
  371.  
  372.  
  373.   if(languages.empty())    cout << "Yes" << endl;
  374.   else                     cout << "No"  << endl;
  375.  
  376.  
  377.   cout << "Pushing elements..." << endl;
  378.  
  379.  
  380.   languages.push("Python");                               // push element into the queue
  381.   languages.push("C++"   );
  382.  
  383.   cout << "Is the queue empty? ";
  384.  
  385.   int nSize;
  386.  
  387.   if(languages.empty())                                    // check if the queue is empty  
  388.   {
  389.      cout << "Yes";
  390.   }
  391.   else
  392.   {
  393.      cout <<  "No \t";
  394.      nSize = languages.size();                            //   get the size of the queue
  395.      cout << "Size of the queue: " << nSize;
  396.   }
  397.  
  398. return 0;
  399. }
  400.  
  401. */
  402.  
  403.  
  404. //  VECTOR  ///////////////////////////////////////////////////////////////////////////////////
  405.  
  406. /*
  407. #include <iostream>
  408. #include   <vector>
  409. using namespace std;
  410.  
  411. ////////////////////////////////////////////////////////////
  412. int main()                                                //
  413. {
  414.    
  415.     int arr[] = {51, 52, 53, 54, 55};
  416.    
  417.     for(int i : arr)                           //  foreach-öèêë
  418.     {
  419.         std::cout << i << ' ';
  420.     }
  421.     std::cout << std::endl;
  422.    
  423.    
  424.     std::vector<int> vec = {1, 2, 3, 4, 5};
  425.  
  426.    // for(const int& element : vec)
  427.    // for(int i : vec)
  428. //  {
  429.   //      std::cout << i << " ";
  430.   //  }
  431.    
  432.    
  433.     for(int i = 0; i < 3; i++)
  434.     {
  435.         cout << vec[i] << " ";
  436.     }
  437.  
  438. return 0;
  439. }
  440. */
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. /*
  469. #include  <iostream>
  470. #include    <vector>
  471. using namespace std;
  472.  
  473.  
  474. ////////////////////////////////////////////////////////////
  475. int main()                                                //
  476. {
  477.  
  478.   vector<int> vector1 = {71,  72, 73, 74,  75};           //       initializer list
  479.   vector<int> vector2   { 6,   7,  8,  9,  10};           // uniform initialization
  480.  
  481.   vector<int> vector3(5, 12);                             //               method 3
  482.  
  483.   cout << "vector1 = ";
  484.   for(int i = 0; i < vector1.size(); i++)  
  485.   {
  486.       cout << vector1[i] << "  ";
  487.   }
  488.  
  489.   cout << "\nvector2 = ";
  490.   for(const int& i : vector2)                             // ranged loop
  491.   {
  492.       cout << i << "  ";
  493.   }
  494.  
  495.   cout << "\nvector3 = ";
  496.   for(int i : vector3)                                    // ranged loop
  497.   {
  498.       cout << i << "  ";
  499.   }
  500.  
  501. return 0;
  502. }
  503. */
  504.  
  505.  
  506.  
  507. /*
  508.  
  509.  
  510.  
  511. #include  <iostream>
  512. #include    <vector>
  513. using namespace std;
  514.  
  515.  
  516. ////////////////////////////////////////////////////////////
  517. int main()                                                //
  518. {
  519.    
  520.   vector<int> num {1, 2, 3, 4, 5};
  521.  
  522.   cout << "Initial Vector: ";
  523.  
  524.   for(const int& i : num)
  525.   {
  526.       cout << i << "  ";
  527.   }
  528.  
  529.   num.push_back(6);                                       // add the integers 6 and 7 to the vector
  530.   num.push_back(7);
  531.  
  532.   cout << "\nUpdated Vector: ";
  533.  
  534.  
  535.   for( int i : num)
  536.   {
  537.       cout << i << "  ";
  538.   }
  539.  
  540. return 0;
  541. }
  542.  
  543. */
  544. /*
  545.  
  546. #include  <iostream>
  547. #include    <vector>
  548. using namespace std;
  549.  
  550. ////////////////////////////////////////////////////////////
  551. int main()                                                //
  552. {  
  553.    
  554.   vector<int> num {1, 2, 3, 4, 5};
  555.  
  556.   cout << "Element at Index 0: " << num.at(0) << endl;
  557.   cout << "Element at Index 0: " << num[1]    << endl;
  558.   cout << "Element at Index 2: " << num.at(2) << endl;
  559.   cout << "Element at Index 4: " << num.at(4);
  560.  
  561.   return 0;
  562. }
  563.  
  564. */
  565.  
  566.  
  567.  
  568. /*
  569.  
  570. #include   <iostream>
  571. #include     <vector>
  572. using namespace  std;
  573.  
  574.  
  575. //////////////////////////////////////////////////////////
  576. int main()                                              //
  577. {
  578.    
  579.   vector<int> num {1, 2, 3, 4, 5};
  580.  
  581.   cout << "Initial Vector: ";
  582.  
  583.   for(const int& i : num)
  584.   {
  585.       cout << i << "  ";
  586.   }
  587.  
  588.   num.at(1)  =    9;                                          // change elements at indexes 1 and 4
  589.   num[3]     =  777;
  590.   num.at(4)  =    7;
  591.  
  592.  // num.at(14) = 17;                                        // Error
  593.   cout << "\nUpdated Vector: ";
  594.  
  595.   for(const int& i : num)
  596.   {
  597.     cout << i << "  ";
  598.   }
  599.  
  600. return 0;
  601. }
  602. */
  603.  
  604.  
  605. /*
  606.  
  607. #include   <iostream>
  608. #include     <vector>
  609. using namespace  std;
  610.  
  611.  
  612. //////////////////////////////////////////////////////////
  613. int main()                                              //
  614. {
  615.    
  616.   vector<int> prime_numbers{2, 3, 5, 7};
  617.  
  618.  
  619.   cout << "Initial Vector: ";                           // initial vector
  620.   for(int i : prime_numbers)
  621.   {
  622.       cout << i << " ";
  623.   }
  624.  
  625.  
  626.   prime_numbers.pop_back();                             // remove the last element
  627.  
  628.  
  629.   cout << "\nUpdated Vector: ";  // final vector
  630.   for(int i : prime_numbers)
  631.   {
  632.       cout << i << " ";
  633.   }
  634.  
  635. return 0;
  636. }
  637.  
  638. */
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement