| | |
How to recursively find a value in a linked list
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 16
Reputation:
Solved Threads: 0
Hi
I have a method that has a reference to a linked list and an int that is the value. I want to recursively call that value to count and return how often that value is in the linked list.
So, here is what I got:
is that right?
I have a method that has a reference to a linked list and an int that is the value. I want to recursively call that value to count and return how often that value is in the linked list.
So, here is what I got:
Java Syntax (Toggle Plain Text)
public static int find(LinkedNode x, int value){ if (x.value != value){ return 0; } else{ return 1+ find(x.next, value); } }
•
•
Join Date: Sep 2008
Posts: 1,652
Reputation:
Solved Threads: 206
0
#6 Oct 10th, 2009
You just want to count how many times a value is in the linked list? If so, I don't see how your method could work.
if (x.value != value){
return 0;
}
The first time the value isn't at the node, it will stop, even if the value is found at some later node in the list. Right?
if (x.value != value){
return 0;
}
The first time the value isn't at the node, it will stop, even if the value is found at some later node in the list. Right?
Last edited by BestJewSinceJC; Oct 10th, 2009 at 4:28 pm.
Out.
![]() |
Similar Threads
- Code Snippet: Reversing a linked list - recursively. (C)
- Sorting/Returning a Linked List (C++)
- Need help with initializing items in linked list in a new way (C)
- Yet another linked list question (C++)
- Swapping in a linked list (C++)
- Reversing singly linked list? (C++)
- how to find maximum value in linked list ?? please help. (C)
- recursive linked list (C++)
- Bumping my object on a linked list (C++)
- linked list library (C)
Other Threads in the Java Forum
- Previous Thread: I need help with doing my Java homework.
- Next Thread: Complexity Class Estimate: Big O
Views: 883 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for count, linked, list, recursion
algorithm array arrays base binary button c# c++ character class command conversion count counttheoccurenceofanintegerinthe10inputs database digit directory display distinct dropdown dynamic echo executable factorial fflush fgets file filename frequency ftp function functions initialization input inputs integer interation iteration java link linked linux list lists math media method news number numerical object occurence order output password pointer pointers prime python query radio radix ratings record recursion recursive resultset return running scanf security select social sorting sql statistics string tables tree tuple update user view word







