C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2013, 03:04 AM
sergerde sergerde is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 sergerde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 21 sec
Reputation Power: 0
How to find the even numbers in a given linked list by using recursion?

I could do better things in the first day of the year but i'm trying to implement the linked lists and recursion together.

I just thought that how I can achieve to write a function that calculates the even numbers in a linked list with recursion.

This is a draft of the recursion code i know this is wrong but how should I implement the code?

void List:: findingEvens(Node* n){
if(n == NULL)
return;
else
if(n-> data % 2 != 0)
findingEvens(n-> next);
else
findingEvents(n-> next);
}

Reply With Quote
  #2  
Old January 1st, 2013, 10:19 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,353 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 8 h 3 m 36 sec
Reputation Power: 383
Recursively traversing a singly linked list is not sane.

Misspelling evens as events doesn't look useful.

if (condition) same_action;
else same_action;

is pathetic.

Happy new year. Mine's not starting happy, and I'm passing it along. Sorry.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 2nd, 2013, 02:23 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
how about this pseudocode:

Code:
int findingEvens(node L, int E)

	if(null L)
		return 0;
		
	if(L->element is even)
		if(null L->next)
			return E + 1
		else
			return findingEvens(L->next, E + 1)
	else
		if(null L->next)
			return E
		else
			return findingEvens(L->next, E)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to find the even numbers in a given linked list by using recursion?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap