Skip to content

Commit 6f9b50b

Browse files
committed
adding hasNodeRecursive
1 parent 15999e7 commit 6f9b50b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

OneWayLinkedList.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ int OneWayLinkedList::hasNode(int data) {
8787
return 0;
8888
}
8989

90+
// Check there is a node with a specific data in the list or not (with a recursive function)
91+
int OneWayLinkedList::hasNodeRecursive(int data, Node* node) {
92+
if(node == NULL) return 0;
93+
if(node->data == data) return 1;
94+
return hasNodeRecursive(data, node->next);
95+
}
96+
9097
// Get the first node
9198
Node* OneWayLinkedList::getFirstNode() {
9299
return this->head;

OneWayLinkedList.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class OneWayLinkedList {
5050
// Check there is a node with a specific data in the list or not
5151
int hasNode(int data);
5252

53+
// Check there is a node with a specific data in the list or not (with a recursive function)
54+
int hasNodeRecursive(int data, Node* node);
55+
5356
// Delete a node with a specific data
5457
void deleteNode(int data);
5558

0 commit comments

Comments
 (0)