Found 7347 Articles for C++

How to quickly swap two arrays of the same size in C++?

Ayush Gupta
Updated on 02-Mar-2020 10:41:17

179 Views

In this tutorial, we will be discussing a program to understand how to quickly swap two arrays of same size in C++.For this we will be using a quick method called std::swap() for swapping the elements of the two given arrays.Example Live Demo#include #include using namespace std;    int main (){    int a[] = {1, 2, 3, 4};    int b[] = {5, 6, 7, 8};    int n = sizeof(a)/sizeof(a[0]);    swap(a, b);    cout

How to print a semicolon(;) without using semicolon in C/C++?

Ayush Gupta
Updated on 02-Mar-2020 10:38:18

248 Views

In this tutorial, we will be discussing a program to understand how to print a semicolon(;) without using a semicolon in /C++.This can be done in two possible ways, either by using the ascii value of semicolon or using user-defined macros for the same.Example Live DemoUsing putchar() method#include int main(){    //ASCII value of semicolon is equal to 59    if (putchar(59)){    }    return 0; }Output;Example Live DemoUsing Macros :#include #define POINT printf("%c",59) int main(){    if (POINT) {    } }Output;

How to join two Vectors using STL in C++?

Ayush Gupta
Updated on 02-Mar-2020 10:27:32

170 Views

In this tutorial, we will be discussing a program to understand how to join two given vectors using STL library in C++.To join two given vectors we would be using the set_union() method from the STL library.Example Live Demo#include using namespace std; int main(){    //collecting the vectors    vector vector1 = { 1, 45, 54, 71, 76, 12 };    vector vector2 = { 1, 7, 5, 4, 6, 12 };    sort(vector1.begin(), vector1.end());    sort(vector2.begin(), vector2.end());    cout

deque::at() and deque::swap() in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 09:33:32

163 Views

In this article we are going to discuss the deque::at() and deque::swap() function in C++ STL function syntax, working and its return values.What is deque::at() and deque::swap() function in STL?Deque or Double ended queues are as name suggests, sequence containers which can be expanded or contracted at both the ends. The user can easily insert data from any of the ends and similarly delete data from any of the ends. They are similar to vectors, but the only difference is that unlike vectors, contiguous storage allocation may not be guaranteed. Still Deque is more efficient in case of insertion and ... Read More

list pop_back() function in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 09:29:35

2K+ Views

In this article we will be discussing the working, syntax and examples of list::pop_back() function in C++.What is a List in STL?List is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is list::pop_back()?list::pop_back() ... Read More

list merge() function in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 09:25:51

3K+ Views

In this article we will be discussing the working, syntax and examples of list::merge() function in C++.What is a List in STL?List is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is list::merge()?list::merge() ... Read More

list erase() function in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 09:16:59

916 Views

In this article we will be discussing the working, syntax and examples of list::erase() function in C++.What is a List in STL?List is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is list::erase()?list::erase() ... Read More

forward_list::remove() in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 09:13:38

278 Views

In this article we will be discussing the working, syntax and examples of forward_list::remove() and forward_list::remove_if() functions in C++.What is a Forward_list in STL?Forward list are sequence containers that allow constant time insert and erase operations anywhere within the sequence. Forward list are implement as a singly-linked lists. The ordering is kept by the association to each element of a link to the next element in the sequence.What is forward_list::remove()?forward_list::remove() is an inbuilt function in C++ STL which is declared in header file. remove() is used to removes all the elements from the forward_list. The container size is decresed by ... Read More

forward_list::push_front() and forward_list::pop_front() in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 08:50:00

223 Views

In this article we will be discussing the working, syntax and examples of forward_list::push_front() and forward_list::pop_front() functions in C++.What is a Forward_list in STL?Forward list are sequence containers that allow constant time insert and erase operations anywhere within the sequence. Forward list are implement as a singly-linked lists. The ordering is kept by the association to each element of a link to the next element in the sequence.What is forward_list::push_front()?forward_list::push_front() is an inbuilt function in C++ STL which is declared in header file. push_front() is used to push/insert an element or a value in the front or at the beginnig ... Read More

list size() function in C++ STL

Sunidhi Bansal
Updated on 02-Mar-2020 08:15:26

7K+ Views

In this article we will be discussing the working, syntax and examples of list::size() function in C++.What is a List in STL?List is a data structure that allows constant time insertion and deletion anywhere in sequence. Lists are implemented as doubly linked lists. Lists allow non-contiguous memory allocation. List perform better insertion extraction and moving of element in any position in container than array, vector and deque. In List the direct access to the element is slow and list is similar to forward_list, but forward list objects are single linked lists and they can only be iterated forwards.What is list::size()?list::size() ... Read More

Advertisements