Skip to content

Commit 09f5852

Browse files
committed
Add search method to LinkedList class
Add newline at end of recursion.java file
1 parent c07293e commit 09f5852

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

linkedlist.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ def __repr__(self):
3030
nodes.append(f"[{current.data}]")
3131
current = current.next_node
3232
return '-> '.join(nodes)
33+
34+
35+
def search(self,value):
36+
"""Search the linked list for a node with the requested value and return the node."""
37+
current = self.head
38+
while current:
39+
if current.data == value:
40+
return current
41+
current = current.next_node
42+
return None
3343

3444
def is_empty(self):
3545
"""Return True if the list is empty."""

recursion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ int main()
1010
// Print the value of 'num2' to the console using printf function with format specifier %.2f. This will display only two decimal
1111
return 0;
1212
}
13+
14+

recursion.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public static void main(String[] args)
77

88
System.out.println(myrec.doRecursion(4));
99
}
10+
11+
1012
}

0 commit comments

Comments
 (0)