File tree Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Expand file tree Collapse file tree 4 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
# cplusplus-forward_list
2
2
Demo implementation of c++ forward list
3
3
4
+ 1 . Two ways of implementing it: Inner class/friend class. I used friend class because it is easier to read the code separated in different files.
5
+ https://web.stanford.edu/class/cs107l/handouts/04-Custom-Iterators.pdf | https://stackoverflow.com/questions/7758580/writing-your-own-stl-container
4
6
Todo's:
5
7
1 . Add functionality to push back
6
8
2 . add const iterator
Original file line number Diff line number Diff line change 2
2
#define FORWARD_LIST_FORWARD_TLIST_H
3
3
4
4
#include " forward_tlist_node.h"
5
+ #include < cstddef>
5
6
6
7
namespace tlib {
7
8
template <typename T>
8
9
class forward_tlist {
9
10
using iterator = tlib::forward_tlist_iterator<T>;
10
11
public:
11
- forward_tlist (): head(nullptr ), tail(nullptr ) {};
12
+ forward_tlist (): head(nullptr ), tail(nullptr ), size_( 0 ) {};
12
13
~forward_tlist () { delete head; }
13
14
bool empty () { return head == nullptr ; }
14
- void push_back (const T& element);
15
+ std::size_t size () const ;
16
+ /* *
17
+ * Prepends the given element to the beginning of the container
18
+ * No iterators are invalidated
19
+ * @param element the value of the element to prepend
20
+ */
21
+ void push_front (const T& element);
15
22
iterator begin () { return forward_tlist_iterator<T>(head); }
16
23
iterator end () { return forward_tlist_iterator<T>(nullptr ); }
17
24
18
25
private:
26
+ std::size_t size_;
19
27
forward_tlist_node<T> *head;
20
28
forward_tlist_node<T> *tail;
21
29
};
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ namespace tlib {
16
16
17
17
private:
18
18
forward_tlist_node<T> *pointee;
19
- forward_tlist_iterator (forward_tlist_node<T> *pointee): pointee(pointee) {}
19
+ explicit forward_tlist_iterator (forward_tlist_node<T> *pointee): pointee(pointee) {}
20
20
21
21
}; // class forward_tlist_iterator
22
22
} // namespace tlib
Original file line number Diff line number Diff line change
1
+ #include " forward_tlist/forward_tlist.h"
2
+
3
+ template <typename T>
4
+ void tlib::forward_tlist<T>::push_front(const T &element) {
5
+
6
+ }
You can’t perform that action at this time.
0 commit comments