Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename T>
- T foo(T t);
- /////////////////////////////////////////////////////
- int main()
- {
- cout << foo(3) << " - " << foo(3.0) << endl;
- }
- template<typename T>
- /////////////////////////////////////////////////////
- T foo(T t)
- {
- return t/2;
- }
- /*
- #include <iostream>
- using namespace std;
- int foo(int n);
- double foo(double n);
- /////////////////////////////////////////////////////
- int main()
- {
- cout << foo(3) << " - " << foo(3.0) << endl;
- }
- /////////////////////////////////////////////////////
- int foo(int n)
- {
- return n/2;
- }
- /////////////////////////////////////////////////////
- double foo(double f) //
- {
- return f/2;
- }
- */
- /*
- #include <stdio.h>
- void foo(int n);
- /////////////////////////////////////////////////////
- int main()
- {
- int n = 100;
- foo(n);
- printf("n from matn = %d\n", n);
- }
- //////////////////////////////////////////////////////
- void foo(int n)
- {
- n = n - 77;
- }
- */
- /*
- #include <iostream>
- #include <queue>
- using namespace std;
- //////////////////////////////////////////////////////////////////////
- int main()
- {
- queue<string> animals; // create a queue of string
- animals.push("Cat"); // push elements into the queue
- animals.push("Dog");
- cout << "Queue: ";
- while(animals.empty() != 1) // print elements of queue loop until queue is empty
- {
- cout << animals.front() << ", "; // print the element
- animals.pop(); // pop element from the queue
- }
- cout << endl;
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <queue>
- using namespace std;
- void display_queue(queue<string> q); // function prototype for display_queue utility
- /////////////////////////////////////////////////////
- int main()
- {
- queue<string> animals; // create a queue of string
- animals.push("Cat"); // push element into the queue
- animals.push("Dog");
- animals.push("Fox");
- cout << "Initial Queue: ";
- display_queue(animals);
- animals.pop(); // remove element from queue
- cout << "Final Queue: ";
- display_queue(animals);
- return 0;
- }
- ///////////////////////////////////////////////// utility function to display queue
- void display_queue(queue<string> q)
- {
- while(q.empty() != 1)
- {
- cout << q.front() << ", ";
- q.pop();
- }
- cout << endl;
- }
- */
- /*
- #include <iostream> // push()
- #include <queue> // front()
- using namespace std; // back()
- ////////////////////////////////////////////////////////////
- int main() //
- {
- queue<int> nums; // create a queue of int
- for(int i = 0; i < 97; i++)
- {
- nums.push(i+10);
- }
- // // push element into the queue
- // nums.push(2);
- // nums.push(3);
- int front = nums.front(); // get the element at the front
- int back = nums.back (); // get the element at the back
- cout << "First element: " << front << endl;
- cout << "Last element: " << back << endl;
- return 0;
- }
- */
- /*
- #include <iostream> // push()
- #include <queue> // size()
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- queue<string> languages; // create a queue of string
- languages.push("Python"); // push element into the queue
- languages.push("C++" );
- languages.push("Java" );
- int size = languages.size(); // get the size of the queue
- cout << "Size of the queue: " << size;
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <queue>
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main()
- {
- queue<string> languages; // create a queue of string
- cout << "Is the queue empty? ";
- if(languages.empty()) cout << "Yes" << endl;
- else cout << "No" << endl;
- cout << "Pushing elements..." << endl;
- languages.push("Python"); // push element into the queue
- languages.push("C++" );
- cout << "Is the queue empty? ";
- int nSize;
- if(languages.empty()) // check if the queue is empty
- {
- cout << "Yes";
- }
- else
- {
- cout << "No \t";
- nSize = languages.size(); // get the size of the queue
- cout << "Size of the queue: " << nSize;
- }
- return 0;
- }
- */
- // VECTOR ///////////////////////////////////////////////////////////////////////////////////
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- int arr[] = {51, 52, 53, 54, 55};
- for(int i : arr) // foreach-öèêë
- {
- std::cout << i << ' ';
- }
- std::cout << std::endl;
- std::vector<int> vec = {1, 2, 3, 4, 5};
- // for(const int& element : vec)
- // for(int i : vec)
- // {
- // std::cout << i << " ";
- // }
- for(int i = 0; i < 3; i++)
- {
- cout << vec[i] << " ";
- }
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> vector1 = {71, 72, 73, 74, 75}; // initializer list
- vector<int> vector2 { 6, 7, 8, 9, 10}; // uniform initialization
- vector<int> vector3(5, 12); // method 3
- cout << "vector1 = ";
- for(int i = 0; i < vector1.size(); i++)
- {
- cout << vector1[i] << " ";
- }
- cout << "\nvector2 = ";
- for(const int& i : vector2) // ranged loop
- {
- cout << i << " ";
- }
- cout << "\nvector3 = ";
- for(int i : vector3) // ranged loop
- {
- cout << i << " ";
- }
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> num {1, 2, 3, 4, 5};
- cout << "Initial Vector: ";
- for(const int& i : num)
- {
- cout << i << " ";
- }
- num.push_back(6); // add the integers 6 and 7 to the vector
- num.push_back(7);
- cout << "\nUpdated Vector: ";
- for( int i : num)
- {
- cout << i << " ";
- }
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- ////////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> num {1, 2, 3, 4, 5};
- cout << "Element at Index 0: " << num.at(0) << endl;
- cout << "Element at Index 0: " << num[1] << endl;
- cout << "Element at Index 2: " << num.at(2) << endl;
- cout << "Element at Index 4: " << num.at(4);
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- //////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> num {1, 2, 3, 4, 5};
- cout << "Initial Vector: ";
- for(const int& i : num)
- {
- cout << i << " ";
- }
- num.at(1) = 9; // change elements at indexes 1 and 4
- num[3] = 777;
- num.at(4) = 7;
- // num.at(14) = 17; // Error
- cout << "\nUpdated Vector: ";
- for(const int& i : num)
- {
- cout << i << " ";
- }
- return 0;
- }
- */
- /*
- #include <iostream>
- #include <vector>
- using namespace std;
- //////////////////////////////////////////////////////////
- int main() //
- {
- vector<int> prime_numbers{2, 3, 5, 7};
- cout << "Initial Vector: "; // initial vector
- for(int i : prime_numbers)
- {
- cout << i << " ";
- }
- prime_numbers.pop_back(); // remove the last element
- cout << "\nUpdated Vector: "; // final vector
- for(int i : prime_numbers)
- {
- cout << i << " ";
- }
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement