Originally Posted by
whiteflags
Good pseudo code starts with a laundry list of tasks to do and an explanation of data. Then you just have to drill down until it looks like an implementation.
But I'm talking about pseudo code to give an idea, not design from scratch toward implementation.
Originally Posted by
manasij7479
I always find pseudo-code (like the ones given in the Cormen book, which I'm reading now) very confusing in terms of translating ideas(maybe that is because I'm much more familiar with C++ than with, say python or pascal).
So don't use that style of pseudo code.
std100093's code:
Code:
int findMax(int* data,const int n)
{
int max=data[0];
for(int i=1 ; i<n ; i++)
if(max<data[i])
max=data[i];
return max;
}
in pseudo code:
Code:
function findMax(data [as array], n [as amount of data])
set max to first element of data
loop using I through the elements of data
test if max less than data[I]
if so replace max with data[I]
return max
No code that can be directly copied
The OP must still think about the small details of the code (what loop to use; loop parameters)
They still learn with guidance, not get confused with gobbeldy-gook like
Code:
std::vector<int> data={1,4,3,4,5,6,0,3}; // they barely know what an array is, how is this syntax going to help them?
for(auto x:data) // what is an auto? All I've learned is for(i=1; i<n; i++)
std::cout<<(x>i?"*":" ")<<"\t"; // what's this std thing? What's the ?"*":"" mean? Doesn't cout work?
// I've never seen anything like this in my like! I'm suppose to learn something from this?
Target your audience. Don't show them neurosurgery when all they know is a band-aid.