|
-
October 4th, 2012, 07:25 AM
#25
Re: A task involving linked lists and a headache
You have a number of issues with your code that could be improved.
You need to get the next pointer out of your Bunny Class.
Your use of Random makes little sense. You're doing weird things like saying Random(10) to determine sex, when it seems like Random(2) would make more sense. Same with color.
You'd be better off storing attributes as ordinal values rather than string literals. Then you could do things like
sex = Random(2);
without all those if statements. If you use enums or const ints rather than string literals, the compiler will catch it if you make a spelling mistake, whereas it won't with string literals.
What's the difference between size and BunnyCount in your list?
Why are you writing things like
Name=Names[rand()%(14-10)+10
Why not just write 4 if you mean 4?
If you maintained a pointer to the tail of your list, you wouldn't have to iterate the list every time you add a bunny.
There are other issues but if you're so inclined, you could start with them.
Last edited by GCDEF; October 4th, 2012 at 07:33 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|