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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- Difference between forward list and list in C++
- 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++
- Inline Functions in C++
- Macros vs Functions
- C++ Mathematical Functions
- Nested functions in C
- Pure Functions
- Searching in a map using std::map functions in C++
- C | Functions | Question 3
- Static functions in C
- Functions that cannot be overloaded in C++
- C | Functions | Question 5
- C | Functions | Question 6
- C | Functions | Question 7
- C | Functions | Question 8
Improved By : mohitKHATRI1