Skip to content

Commit c63b404

Browse files
committed
add resources to readme
1 parent e7f3690 commit c63b404

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# cplusplus-forward_list
22
Demo implementation of c++ forward list
33

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
46
Todo's:
57
1. Add functionality to push back
68
2. add const iterator

include/forward_tlist/forward_tlist.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22
#define FORWARD_LIST_FORWARD_TLIST_H
33

44
#include "forward_tlist_node.h"
5+
#include <cstddef>
56

67
namespace tlib{
78
template <typename T>
89
class forward_tlist{
910
using iterator = tlib::forward_tlist_iterator<T>;
1011
public:
11-
forward_tlist(): head(nullptr), tail(nullptr) {};
12+
forward_tlist(): head(nullptr), tail(nullptr), size_(0) {};
1213
~forward_tlist() { delete head; }
1314
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);
1522
iterator begin() { return forward_tlist_iterator<T>(head); }
1623
iterator end() { return forward_tlist_iterator<T>(nullptr); }
1724

1825
private:
26+
std::size_t size_;
1927
forward_tlist_node<T> *head;
2028
forward_tlist_node<T> *tail;
2129
};

include/forward_tlist/forward_tlist_iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace tlib {
1616

1717
private:
1818
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) {}
2020

2121
}; //class forward_tlist_iterator
2222
} //namespace tlib

src/forward_tlist/forward_tlist.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
}

0 commit comments

Comments
 (0)