Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Error in my recursive pseudo code

pseudo code pseudocode recursive

  • Please log in to reply
2 replies to this topic

#1 Monster92

Monster92

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 05 February 2012 - 02:52 PM

Ok I have written a program samelist(List1, List2). IT is supposed to check two lists for equality. However whenever I try to implement it in Java it doesn't work. A friend told me it is with the pseudo code I have written shown below. There's a mistake there but I cannot see it. Sorry again to be cheeky but if you find a way to correct can you provide an example of how it would work?


samelist(L1,L2) {  
if(L1==[] and L2==[]) return true;
	else return (head(L1)==head(L2) and samelist(tail(L1), tail(L2))); 
}

  • 0

#2 Sysop_fb

Sysop_fb

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 151 posts
  • Location:Missouri

Posted 05 February 2012 - 02:58 PM

I don't see any form of returning false in your psuedo code also you don't need to keep doing a return statement.
If end of list then return true
else If head of list a == head of list b then recursively call function with tail of lists
else return false

You basically end up using if statements as a type of pattern matching. When doing pattern matching you need to have a pattern for every logical potential.
  • 0
"The best optimizer is between your ears" - Michael Abrash
Saying you can optimize a program is like saying you understand how a program works on every level of every facet on a specific machines configuration.

#3 Monster92

Monster92

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 05 February 2012 - 03:05 PM

I'm apologize for my ignorance I don't see how that could be written. I'm new to the idea of pseudo code and programming at large
  • 0





Also tagged with one or more of these keywords: pseudo code, pseudocode, recursive

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download