aboutsummaryrefslogtreecommitdiffstats
path: root/C++/Recursion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'C++/Recursion.cpp')
-rw-r--r--C++/Recursion.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/C++/Recursion.cpp b/C++/Recursion.cpp
index 97f772b..cd60f0a 100644
--- a/C++/Recursion.cpp
+++ b/C++/Recursion.cpp
@@ -99,3 +99,24 @@ void deallocateList(linkNode* &hdList) {
delete tmpNode;
}
}
+
+int countEqual(linkNode* hdList, list_t el) {
+ int count = 0;
+ while(hdList != NULL) {
+ if(hdList->element == el) {
+ ++count;
+ }
+ hdList = hdList->next;
+ }
+ return count;
+}
+
+int countEqualRec(linkNode* hdList, list_t el, int count) {
+ if(hdList != NULL) {
+ if(hdList->element == el) {
+ ++count;
+ }
+ countEqualRec(hdList->next, el, count);
+ }
+ return count;
+}