Implement a bidirectional linked list
文章目录
A bidirectional linked list is the same as a singular linked list except that there are two links between two nodes.
Here is the specification of my BiLinkedList.
BiLinkedList()
, Create an empty BiLinkedList.BiLinkedList(const BiLinkedList& list)
, Create a BiLinkedList from another BiLinkedListlist
.BiLinkedList(const T& value)
, Create a BiLinkedList whose first element isvalue
.BiLinkedList(const T values[], size_t size)
, Create a BiLinkedList from an arrayvalues
of sizesize
.const BiLinkedList& operator=(const BiLinkedList& list)
, Support BiLinkedList assignment.~BiLinkedList()
, Free all the space requested by the BiLinkedList.std::ostream& operator<<(std::ostream&, const BiLinkedList<T>&);
, Output the BiLinkedList in the form [a, b, c …].void append(const T& value)
, Append an elementvalue
to the BiLinkedList.const T& operator[](size_t index)
, Access the element of the BiLinkedList, but it’s not random accessible.void insert(size_t index, const T& value)
, Insert an elementvalue
in the positionindex
.void remove(size_t index)
, Remove the element in the positionindex
.size_t size()
, Return the size of the BiLinkedList.
Here is the code.