From ee0556730d8c1edfbf3a2bf98cd8e43ff359924b Mon Sep 17 00:00:00 2001 From: Luke Else Date: Tue, 22 Nov 2022 21:28:04 +0000 Subject: [PATCH] #1 Added count method to Linked List --- DataStructures/src/linkedlist.h | 5 +++++ src/main.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/DataStructures/src/linkedlist.h b/DataStructures/src/linkedlist.h index bf95478..9813bab 100644 --- a/DataStructures/src/linkedlist.h +++ b/DataStructures/src/linkedlist.h @@ -101,6 +101,11 @@ namespace Datastructures { return true; } + template + int LinkedList::count() const { + return this->mCount; + } + template int LinkedList::find(const T& value) const { //Start at the head of the list diff --git a/src/main.cpp b/src/main.cpp index d4ed7d3..6f54d42 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include int main() { @@ -5,6 +6,8 @@ int main() { list.append(5); list.append(200); list.insert(20, 2); + std::cout << list.count() << std::endl; //3 list.remove(0); int x = list.find(10); + std::cout << list.count() << std::endl; //2 } \ No newline at end of file