Forward list is a sequence container that allows unidirectional sequential access to its data. It contains data of the same type. In STL, it has been implemented using Singly Linked List, requires constant time for insertion and deletion. Elements of the forward list are scattered in the memory and the ordering is maintained by associating every element of the list by the next element of the list via a link. Thus, it makes efficient use of memory. It has been introduced from the C++11 version.
Implementation of Forward list:
The elements of forward list are : 10 12 13 15
List is also a sequence container that allows bidirectional sequential access to its data. It contains data of the same type. In STL, it has been implemented using Doubly Linked List and it requires constant time for insertion and deletion. It allows non-contiguous memory allocation. Each element of the list is associated with a link to the element following it and preceding it. It is extensively used in sorting algorithm because of its constant insertion and deletion time and bidirectional sequential access.
Implementation of list:
The elements of list are : 1 2 10 15
Tabular difference between forward list and list:
|Implemented using Singly Linked List||Implemented using Doubly Linked List|
|Consumes relatively less memory||Consumes relatively more memory|
|Less overhead in insertion and removal elements due to less pointer per node, thus it gives better performance.||More overhead in insertion and removal elements due to more pointer per node, thus it gives poor performace.|
|Sequential access in forward direction||Sequential access in both forward and reverse direction|
|Generally used when bidirectional sequential access is needed like for implementing chaining in hashing, adjacency list representation of graph, etc.||Generally used when unidirectional sequential access is needed like for implementing binary tree, hash table, stack, etc.|
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 2 (Manipulating Functions)
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- Difference between Singly linked list and Doubly linked list
- Difference between Backward and Forward chaining
- Difference between Feedback and Feed Forward control systems
- Difference Between Vector and List
- Difference between List and ArrayList in Java
- Difference between List and Array in Python
- Difference between List VS Set VS Tuple in Python
- Python | Difference Between List and Tuple
- Difference between List comprehension and Lambda in Python
- list::front() and list::back() in C++ STL
- list::empty() and list::size() in C++ STL
- list::pop_front() and list::pop_back() in C++ STL
- list::remove() and list::remove_if() in C++ STL
- list::emplace_front() and list::emplace_back() in C++ STL
- list::push_front() and list::push_back() in C++ STL
- list::begin() and list::end() in C++ STL
- What are Forward declarations in C++
- Forward Iterators in C++
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.