Skip to content

Commit 6ce6905

Browse files
committed
fix test for linkedlist
1 parent e637da8 commit 6ce6905

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

data-structures/LinkedList/__test__/test_LinkedList.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,21 @@ int main(int argc, char* argv[]) {
188188
assert(list.get_at(1) == 39);
189189
assert(list.front() == 13);
190190
assert(list.back() == 21);
191-
list.pop_at(2); // 13 39
191+
list.push_at(2, 47); // 13 39 47 21
192192
assert(list.empty() == false);
193-
assert(list.size() == 2);
193+
assert(list.size() == 4);
194194
assert(list.get_at(1) == 39);
195195
assert(list.front() == 13);
196-
assert(list.back() == 39);
196+
assert(list.back() == 21);
197+
list.pop_at(2); // 13 39 21
198+
assert(list.empty() == false);
199+
assert(list.size() == 3);
200+
assert(list.get_at(1) == 39);
201+
assert(list.front() == 13);
202+
assert(list.back() == 21);
197203
list.pop_front();
198204
list.pop_back();
205+
list.pop_back();
199206
assert(list.empty() == true);
200207
assert(list.size() == 0);
201208
std::cout << "ALL TEST PASSED!" << std::endl;

data-structures/LinkedList/include/LinkedList.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,8 @@ void LinkedList<T>::push_at(const size_t index, const T &value){
100100
return;
101101
}
102102
_Node *prev = _head;
103-
size_t prev_index = 0;
104-
while(prev_index < index - 1){
103+
for(size_t i = 0; i < index - 1; ++i){
105104
prev = prev->_next;
106-
++prev_index;
107105
}
108106
_Node *new_node = new _Node(value);
109107
new_node->_next = prev->_next;

0 commit comments

Comments
 (0)