More functions are discussed in this article
Some of the operations other than insertions and deletions that can be used in forward lists are as follows :
1. merge() :- This function is used to merge one forward list with other. If both the lists are sorted then the resulted list returned is also sorted.
2. operator “=” :- This operator copies one forward list into other. The copy made in this case is deep copy.
The contents of 2nd forward list after copy are : 1 2 3 The contents of forward list after merge are : 1 1 2 2 3 3
3. sort() :- This function is used to sort the forward list.
4. unique() :- This function deletes the multiple occurrences of a number and returns a forward list with unique elements. The forward list should be sorted for this function to execute successfully.
The contents of forward list after sorting are : 1 1 2 2 3 3 3 The contents of forward list after unique operation are : 1 2 3
5. reverse() :- This function is used to reverse the forward list.
6. swap() :- This function swaps the content of one forward list with other.
The contents of forward list after reversing are : 3 2 1 The contents of 1st forward list before swapping are : 3 2 1 The contents of 2nd forward list before swapping are : 4 5 6 The contents of 1st forward list after swapping are : 4 5 6 The contents of 2nd forward list after swapping are : 3 2 1
7. clear() :- This function clears the contents of forward list. After this function, the forward list becomes empty.
8. empty() :- This function returns true if the list is empty otherwise false.
The contents of forward list are : 1 2 3 The contents of forward list after clearing are : Forward list is empty
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- List in C++ | Set 2 (Some Useful Functions)
- Forward Iterators in C++
- What are Forward declarations in C++
- Implementing Forward Iterator in BST
- Functions in C/C++
- Macros vs Functions
- Searching in a map using std::map functions in C++
- Thread functions in C/C++
- Static functions in C
- Pure Functions
- Functions that cannot be overloaded in C++
- C | Functions | Question 3
- C | Functions | Question 2
- C | Functions | Question 11
Improved By : mohitKHATRI1