Dumping singly linked list into 2 stacks.

This is a discussion on Dumping singly linked list into 2 stacks. within the C++ Programming forums, part of the General Programming Boards category; Hello. I need to figure out how to dump the contents of my singly linked list into 2 stacks (one ...

Dumping singly linked list into 2 stacks.

Hello. I need to figure out how to dump the contents of my singly linked list into 2 stacks (one for men, one for women). I have my singly-linked list, arranged from highest contribution to the lowest, but they need to be placed into 2 separate stacks. Any hints would be appreciated.

Your DumpIntoStack function doesn't really seem to do what its name indicates... I don't really see a use for that function at all. That aside, you need a function that returns the Contributor object stored at a given location/index within the list (call it GetContributor or something). Store this into your c or x variables and have a GetSex member function for your Contributor objects so you can do something like:

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

Thanks.

Thanks for your reply. I am not sure if I'm having an off day or if my brain isn't full comprehending what you're saying, but I am having some difficulty with taking your suggestions and running with it. Could you please provide some more hints or code examples?

I don't see what's so complicated. Maybe looking at the rest of the code is scrambling your brains? j/k Well, basically you loop through each node in the list; and if the node belongs to a man, then push it onto the Men stack; and if it belongs to a woman, then push it onto the Women stack...

What is the whole purpose of having a separate list container and then two stacks? Is it simply so that you can sort them in the list (highest to lowest) and then have the information that ends up in your stacks be in lowest (top) to highest order? Is that sorting the only reason you even have the list? Do you really need to use stacks? If all you need to do is display contributors in lowest to highest order based on contribution, you might be able to just simply use a couple of multiset containers to store all of this information in lowest to highest order by contribution, then you don't need any of the list related code at all:

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens