samelist(L1,L2) {
if(L1==[] and L2==[]) return true;
else return (head(L1)==head(L2) and samelist(tail(L1), tail(L2)));
}
2 replies to this topic
#1
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?
|
|
|
#2
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.
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.
"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.
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
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
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top










