C++ Deque swap()C++ Deque swap() function exchanges the content of a given deque with the deque passed in the parameter of same type. Conditions:
SyntaxParametersecond: It is an another deque container whose content is to be swapped with the given deque. Return valueIt does not return any value. Example 1Let's see a simple example Output: After swapping,value of str is: java is a programming language After swapping,value of str1 is: C is a programming language In this example, swap() function swaps the contents of str and str1. Now, str contains "java is a programming language" and str1 contains "C is a programming language". Example 2Let's see a simple example when the both the deques are of different type. Output: error: no matching function for call to 'std::deque<char>::swap(std::deque<int>&) In this example, swap() function throws an error as the type of both the deques are different. Example 3Let's see a simple example when the sizes are different. Output: Content of first deque:10 20 30 40 50 Content of second deque:1 2 3 4 In this example, swap() function swaps the content of first deque with the second deque. Next TopicC++ Deque |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India