Results 1 to 3 of 3
- 11-23-2012, 12:42 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 6
- Rep Power
- 0
count elements in linked list recursively!
Good morning,
I was asked to implement a method which I can count elements in linked list recursively.I tried and it compiles but whenever I run I found stackoverflow error.
here is my trial
public int countRec(){
return countRec1(head);
}
public int countRec1(Link current){
current = head ;
if ( current == null ){
return 0 ;
}
else{
return 1 +countRec1(current.next);
}
any help please? :(
- 11-23-2012, 01:01 PM #2
Re: count elements in linked list recursively!
Guide For New Members
BB Code List - Java Programming Forum
To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-23-2012, 05:17 PM #3
Similar Threads
-
Linked List Class Cons, is this possible to turn into a doubly linked list?
By Googol in forum New To JavaReplies: 0Last Post: 09-25-2012, 04:07 AM -
Outputting Elements of a Linked List
By Grimey in forum New To JavaReplies: 6Last Post: 06-10-2012, 08:03 PM -
How would I count number of nodes in linked list?
By colerelm in forum New To JavaReplies: 2Last Post: 10-17-2011, 06:26 AM -
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
Linked list inside a linked list
By viperlasson in forum New To JavaReplies: 5Last Post: 07-26-2010, 11:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks