26#include <initializer_list>
30#include <unordered_set>
43template <
typename T,
typename Allocator = std::allocator<T>>
52 typename std::allocator_traits<Allocator>::template rebind_alloc<Node>;
53 using node_traits = std::allocator_traits<node_allocator_type>;
77 node_traits::construct(
alloc,std::addressof(n->
data),value);
79 node_traits::deallocate(
alloc,n,1);
87 node_traits::destroy(
alloc,std::addressof(n->data));
88 node_traits::deallocate(
alloc,n,1);
104 template <
typename It>
116 curr = &((*curr)->next);
131 for(
const T& it: arr){
135 curr = &((*curr)->next);
150 while(temp !=
nullptr){
170 while(temp !=
nullptr){
191 others.head->
next =
nullptr;
192 others.tail = others.head;
201 head->next = others.head->next;
206 others.head->next =
nullptr;
207 others.tail = others.head;
271 return &(
node->data);
329 return head->next->data;
364 return std::numeric_limits<T>::max() /
sizeof(
Node);
367 return this->tail->
data;
375 while(slow && fast && fast->
next !=
nullptr){
387 while(slow && fast && fast->
next){
407 head->next = new_node;
419 head->next = new_node;
474 }
else if(!
head->next->next){
477 tail->next =
nullptr;
487 tail->next =
nullptr;
544 curr->
next = new_node;
554 curr->
next = new_node;
568 curr->
next = new_node;
574 Node* n_tail = new_node;
575 for(
int i = 0;i < n - 1;i++){
581 curr->
next = new_node;
595 curr->
next = new_node;
601 Node* n_tail = new_node;
602 for(
int i = 0;i < n - 1;i++){
608 curr->
next = new_node;
614 template<std::input_iterator It>
615 requires (!std::same_as<It,Iterator>)
620 Node* n_tail = new_node;
625 n_tail->
next = n_node;
630 curr->
next = new_node;
641 Node* n_tail = new_node;
642 new_head = new_head->
next;
643 while(new_head !=
end){
645 n_tail->
next = n_node;
647 new_head = new_head->
next;
651 curr->
next = new_node;
702 Node* prev =
nullptr;
704 while(curr !=
nullptr){
723 void assign(std::size_t n,
const T& value){
726 for(std::size_t i = 0;i < n;i++){
735 for(std::size_t i = 0;i < n;i++){
741 void assign(std::initializer_list<T> arr){
744 head->next =
nullptr;
747 for(
const T& value: arr){
749 curr = &((*curr)->next);
753 template<
typename It>
840 others.head->next =
nullptr;
841 others.tail = others.head;
850 if(other_begin == other_end){
854 auto moved = (std::distance(first, last)) - 1;
856 others.
size -= moved;
858 Node* last_node = other_begin;
860 while(last_node->
next != other_end){
861 last_node = last_node->
next;
866 curr->
next = other_begin;
870 if(after_node ==
tail || other_end ==
nullptr){
875 if(other_end ==
nullptr){
886 if(other_begin == other_end){
890 auto moved = std::distance(std::next(first),(last));
892 Node* last_node = other_begin;
893 others.size -= moved;
895 while(last_node->
next != other_end){
896 last_node = last_node->
next;
901 curr->
next = other_begin;
906 if(after_node ==
tail){
911 if(other_end ==
nullptr){
924 others.head = tempHead;
928 others.tail = tempTail;
932 others.size = tempSize;
941 others.head = tempHead;
945 others.tail = tempTail;
949 others.size = tempSize;
953 if (!left)
return right;
954 if (!right)
return left;
965 template<
typename compare = std::less<T>>
967 if (!left)
return right;
968 if (!right)
return left;
970 if (comp(left->
data, right->
data)) {
982 while(fast && fast->
next){
995 middle->
next =
nullptr;
998 return merge(left,right);
1000 template <
typename compare>
1008 middle->
next =
nullptr;
1011 return merge(left,right,comp);
1017 while(curr && curr->
next){
1022 template <
typename Compare = std::less<T>>
1023 void sort(Compare comp = Compare{}) {
1028 while (curr && curr->next) {
1035 if(
this == &others){
1039 Node* temp = &dummy;
1040 temp->
next =
nullptr;
1055 if(curr !=
nullptr){
1058 }
else if(pos !=
nullptr){
1071 head->next = dummy.next;
1074 if(
this == &others){
1078 Node* temp = &dummy;
1079 temp->
next =
nullptr;
1094 if(curr !=
nullptr){
1097 }
else if(pos !=
nullptr){
1104 size += others.size;
1107 others.head->next =
nullptr;
1110 head->next = dummy.next;
1112 template <
typename compare = std::less<T>>
1114 if(
this == &others){
1118 Node* temp = &dummy;
1119 temp->
next =
nullptr;
1123 if(comp(curr->data, pos->data)){
1134 if(curr !=
nullptr){
1137 }
else if(pos !=
nullptr){
1150 head->next = dummy.next;
1152 template <
typename compare = std::less<T>>
1154 if(
this == &others){
1158 Node* temp = &dummy;
1159 temp->
next =
nullptr;
1163 if(comp(curr->data, pos->data)){
1174 if(curr !=
nullptr){
1177 }
else if(pos !=
nullptr){
1190 head->next = dummy.next;
1194 if(
this == &others){
1216 if(
this == &others){
1248 }
else if(count >
size){
1249 while(
size < count){
1254 while(
size > count){
1260 void resize(std::size_t count,
const T& value){
1263 }
else if(count >
size){
1264 while(
size < count){
1269 while(
size > count){
1279 std::unordered_set<T>seen;
1285 while(fast !=
nullptr){
1286 if(seen.find(fast->
data) != seen.end()){
1292 if(_next !=
nullptr){
1299 seen.insert(fast->
data);
1308 if(fast ==
nullptr){
1311 while(fast && fast->
next){
1325 template<std::ranges::input_range R>
1330 for(
auto&& elem: rg){
1336 curr->
next = new_node;
1348 for(
const T& x: arr){
1375 while(curr->
next !=
nullptr){
1379 curr->
next =
nullptr;
1381 tail->next =
nullptr;
1409 if(pos >=
static_cast<std::size_t
>(
size)){
1416 static_assert(std::is_same_v<
decltype(curr),
Node*>);
1417 static_assert(std::is_same_v<
decltype(
tail),
Node*>);
1419 for(std::size_t i = 0;i < pos;i++){
1425 head->next =
nullptr;
1444 while(curr->
next !=
nullptr){
1448 curr->
next =
nullptr;
1450 tail->next =
nullptr;
1467 template <
class UnaryPred>
1468 requires(std::predicate<UnaryPred&, const T&>)
1475 while(curr !=
nullptr){
1481 if(_next ==
nullptr){
1495 head->next =
nullptr;
1499 template <
class UnaryPred>
1500 requires(std::predicate<UnaryPred&,const T&>)
1505 std::size_t count = 0;
1508 while(curr !=
nullptr){
1514 if(_next ==
nullptr){
1537 std::cout << *
begin <<
" ";
1540 std::cout << std::endl;
1548 template <std::ranges::input_range R>
1573 template<std::ranges::input_range R>
1597 template <
class ... Args>
1606 head->next = new_node;
1610 template <
class ... Args>
1620 new_node->
next = _next;
1621 curr->
next = new_node;
1628 template<
class... Args>
1631 tail->next = new_node;
1639 while(curr !=
nullptr){
1644 head->next =
nullptr;
Definition forward_list.hpp:221
bool operator!=(const Iterator &others) const
Definition forward_list.hpp:285
std::forward_iterator_tag iterator_category
iterator category iterator category adalah label yang menjelaskan kemampuan sebuah
Definition forward_list.hpp:248
T & operator*()
Definition forward_list.hpp:264
Iterator & operator->()
Definition forward_list.hpp:277
T * pointer
Definition forward_list.hpp:251
T & reference
Definition forward_list.hpp:252
Node * node
Definition forward_list.hpp:223
Iterator & operator++()
Definition forward_list.hpp:273
Iterator(Node *n)
Definition forward_list.hpp:253
bool operator==(const Iterator &others) const
Definition forward_list.hpp:288
T value_type
Definition forward_list.hpp:249
std::ptrdiff_t difference_type
Definition forward_list.hpp:250
pointer operator->() const
Definition forward_list.hpp:270
reference operator*() const
Definition forward_list.hpp:267
friend std::ostream & operator<<(std::ostream &os, const Iterator &it)
Definition forward_list.hpp:256
Iterator operator++(int)
Definition forward_list.hpp:280
Node * get_raw() const
Definition forward_list.hpp:291
forward_lists(It begin, It end)
constructor range,adalah constructor yang menginialisasi nilai dari sebuah container dengan element d...
Definition forward_list.hpp:106
Allocator get_allocator() const noexcept
Definition forward_list.hpp:369
bool check_cycle() const noexcept
Definition forward_list.hpp:372
Node * helper(Node *head)
Definition forward_list.hpp:988
void clear()
Definition forward_list.hpp:1637
Iterator end()
iterator yang menunjuk pointer setelah node terakhir(tail)
Definition forward_list.hpp:311
void push_front(T &&data)
method untuk insertion val pada pos front
Definition forward_list.hpp:399
void merge(forward_lists &others, compare comp=compare{})
Definition forward_list.hpp:1113
void sort()
Definition forward_list.hpp:1014
void pop_front()
method untuk deletion val pada pos front
Definition forward_list.hpp:429
node_allocator_type alloc
Definition forward_list.hpp:54
void uniqe()
Definition forward_list.hpp:1305
~forward_lists()
destructor
Definition forward_list.hpp:217
Node * tail
Definition forward_list.hpp:56
void emplace_front(Args &&... args)
Definition forward_list.hpp:1598
void splice_after(const Iterator pos, forward_lists &others, const Iterator first, const Iterator last)
Definition forward_list.hpp:844
typename std::allocator_traits< Allocator >::template rebind_alloc< Node > node_allocator_type
Definition forward_list.hpp:51
void resize(std::size_t count, const T &value)
Definition forward_list.hpp:1260
void assign(It itr1, It itr2)
Definition forward_list.hpp:755
void splice_after(const Iterator pos, forward_lists &others, const Iterator It)
slice after method untuk memindahkan node dari satu list ke list lain tanpa menyalin data,...
Definition forward_list.hpp:781
void push_front(const T &data)
Definition forward_list.hpp:411
std::size_t remove_if_count(UnaryPred p)
Definition forward_list.hpp:1501
Iterator cbefore_begin() const
Definition forward_list.hpp:320
void push_back(T &&value)
Definition forward_list.hpp:457
T back() const noexcept
Definition forward_list.hpp:366
Node * merge(Node *left, Node *right)
Definition forward_list.hpp:952
void assign(std::initializer_list< T > arr)
Definition forward_list.hpp:741
void emplace_back(Args &&... args)
Definition forward_list.hpp:1629
void assign(std::size_t n, T &&value)
Definition forward_list.hpp:732
void insert_after(Iterator iter_position, const T &val)
Definition forward_list.hpp:550
Node * merge(Node *left, Node *right, compare comp)
Definition forward_list.hpp:966
T front()
method getter yang mengembalikan nilai node pada pos front
Definition forward_list.hpp:328
Node * getMiddle(Node *head)
Definition forward_list.hpp:978
void print_all(Iterator begin, Iterator end)
method untuk print semua node list
Definition forward_list.hpp:1535
void insert_after(Iterator Iterator_position, int n, const T &val)
Definition forward_list.hpp:587
void splice_after(const Iterator pos, forward_lists &&others)
Definition forward_list.hpp:824
void push_back(const T &value)
adalah method untuk melakukan insertion dari posisi belakang(tail)
Definition forward_list.hpp:447
forward_lists(std::initializer_list< T > arr)
initializer list constructor
Definition forward_list.hpp:125
void insert_after(Iterator Iterator_position, int n, T &&val)
Definition forward_list.hpp:560
forward_lists & operator=(const forward_lists &others)
Definition forward_list.hpp:157
void reverse()
Definition forward_list.hpp:701
void merge(forward_lists &&others)
Definition forward_list.hpp:1073
Node * head
Definition forward_list.hpp:55
void _destroy_node(Node *n) noexcept
Definition forward_list.hpp:86
Node * _create_node(const T &value)
Allocator explanation Allocator adalah abstraksi cara mengelola memory pada container alih2 melakukan...
Definition forward_list.hpp:74
void merge_sort(forward_lists &&others)
Definition forward_list.hpp:1215
std::size_t remove_count(const T &value)
Definition forward_list.hpp:1438
void erase_after(const Iterator iter_position)
Definition forward_list.hpp:657
void erase_after(const Iterator pos_begin, const Iterator pos_end)
Definition forward_list.hpp:674
void merge(forward_lists &others)
Definition forward_list.hpp:1034
Iterator before_begin()
iterator yang menunjuk dummy node yaitu head
Definition forward_list.hpp:299
void splice_after(const Iterator pos, forward_lists &&others, const Iterator It)
Definition forward_list.hpp:792
void assign_range(R &&rg)
Definition forward_list.hpp:1326
std::allocator_traits< node_allocator_type > node_traits
Definition forward_list.hpp:53
void merge_sort(forward_lists &others)
Definition forward_list.hpp:1193
void remove(const std::size_t pos)
method overload remove,untuk menghapus node pada posisi pos
Definition forward_list.hpp:1405
forward_lists(const Allocator &a)
Definition forward_list.hpp:95
void sort(Compare comp=Compare{})
Definition forward_list.hpp:1023
void splice_after(const Iterator pos, forward_lists &&others, const Iterator first, const Iterator last)
Definition forward_list.hpp:880
void prepend_range(R &&r)
Definition forward_list.hpp:1574
void insert_after(Iterator iter_position, It itr1, It itr2)
Definition forward_list.hpp:616
void insert_after(const Iterator iter_position, Iterator listBegin, const Iterator listEnd)
Definition forward_list.hpp:635
int size
Definition forward_list.hpp:57
int get_size()
method getter yang mengembalilkan jumlah element saat ini
Definition forward_list.hpp:335
std::size_t max_size() const noexcept
mengembalikan jumlah maksimum yang dapat di tampung list
Definition forward_list.hpp:363
forward_lists(forward_lists &&others) noexcept
move constructor dipakai ketika ingin memindahkan node pada list a ke list b
Definition forward_list.hpp:185
Iterator begin()
iterator yang menunjuk node pada element pertama pada list
Definition forward_list.hpp:305
void pop_back()
pop_back adalah method untuk deletion node di posisi tail
Definition forward_list.hpp:471
void assign_range(std::initializer_list< T > arr)
Definition forward_list.hpp:1344
T get_middle() const noexcept
Definition forward_list.hpp:384
void insert_after(Iterator iter_position, T &&val)
Menyisipkan elemen setelah posisi iterator tertentu.
Definition forward_list.hpp:540
void remove_if(UnaryPred p)
Definition forward_list.hpp:1469
forward_lists(const forward_lists &others)
Definition forward_list.hpp:141
bool is_empty()
method getter yang mengembalilkan true jika list empty,sebalik false jika tidak kosong
Definition forward_list.hpp:342
forward_lists & operator=(forward_lists &&others) noexcept
move assignment constructor
Definition forward_list.hpp:198
void swap(forward_lists &others) noexcept
Definition forward_list.hpp:917
Iterator cend() const
Definition forward_list.hpp:317
void resize(std::size_t count)
resize adalah method untuk mengubah ukuran sebuah list
Definition forward_list.hpp:1245
void insert_range_after(const Iterator &pos, R &&r)
method untuk menghapus semua node pada head berguna pada destructor
Definition forward_list.hpp:1549
void uniqe_all()
Definition forward_list.hpp:1278
void swap(forward_lists &&others) noexcept
Definition forward_list.hpp:934
forward_lists()
Definition forward_list.hpp:92
void merge(forward_lists &&others, compare comp=compare{})
Definition forward_list.hpp:1153
Iterator cbegin() const
Definition forward_list.hpp:314
void remove(const T &value)
overload remove untuk menghapus node dengan nilai sama dengan parameter value
Definition forward_list.hpp:1370
Node * helper(Node *head, compare comp)
Definition forward_list.hpp:1001
void splice_after(const Iterator pos, forward_lists &others)
Definition forward_list.hpp:803
void emplace_after(Iterator pos, Args &&... args)
Definition forward_list.hpp:1611
void assign(std::size_t n, const T &value)
Method Assign Assign dipakai untuk mereplace list saat ini dengan list baru overload method assign as...
Definition forward_list.hpp:723
Definition forward_list.hpp:46
T data
Definition forward_list.hpp:47
Node * next
Definition forward_list.hpp:48