The insert function receives a ElementType item with the info to be added in a new node. The insert function needs to look through the list and add the new node in the appropriate spot for it to be alphabetical using the overloaded operator. I"m pretty sure the overloaded operator is messed up as I've been messing around with it for a couple hours now and have gotten nowhere.
If anyone could help me out it would be appreciated. And if any other of the code is needed I can post it.
I'm confused. You haven't even tried to use the operator>= yet. You should post a more complete example that shows us how you are trying to use it.
I will give you a hint. std::string has an operator== defined. There is no need to call c_str() or strcmp when comparing two std::string objects. Also I would think that you want an operator< that takes two objects of the same type so that the usage of the function will seem more intuitive. I guess you can define whichever operator you wish but I think operator< seems more intuitive but that is because many of the std algorithms use operator< by default so that is the one that I am used to seeing defined in these kinds of situations.
I either end up with a runtime error or an empty list with the above code.
As far as there being better ways with the operators and such, its what my instructor has required for this assignment. We were told to use the following overloaders:
I need to see the definition of the node type. What is node? Please post the entire declaration of your list class. In fact you should show the list class declaration and definition along with a small main function that demonstrates the problem. It is hard to understand without seeing the type declaration for all types that you are using. The node is constructed with the elements but how? What is a node?
// Make sure that you are initializing all attributes!
// who knows what count was when you called insert the first time. Are you using a debugger?
list::list() : first(0), count(0) {
}
// Simplify this (not a big deal though)
booloperator==(const ElementType &el, const KeyType &key)
{
return (el.key == key);
}
I'm not sure where you are at with debugging at this point but you ought to be stepping with a debugger and analyzing the state of your class and variables as you go. Always provide default initial values for classes.
Since you are taking user input many things could be happening and I am not sure where specifically you are seeing the run-time errors. I need to know what you have done on your own and what combination of inputs you have tried. You can easily determine where the program is crashing (if it is) using the debugger and if there is something that you don't understand about that follow up with some more questions.
You really should have posted things as one compilable unit. Please edit that previous post and give us exactly what you are compiling and running otherwise I cannot help you any further.
Fox:2000:NTCa
Robert Fox
News Track: Celestial backbone; Foreign hands off China's net; Women and the web; DOE says no nuke access; Worst net nightmare; Sidebar: Ethics quiz
Crawford:2000:FTO
Diane Crawford and Brian K. E. Balke and Steve Wilstrom and Jef Raskin and Pat McGee
Forum: Tackling OO Design Principles; Educational Concerns; Building LEGO Robots
Meeks:2000:EFBa
Brock N. Meeks
Electronic frontier: bugging out: Y2K fallout or business as usual?
Soloway:2000:LEK
Elliot Soloway and Cathleen Norris and Phyllis Blumenfeld and Barry Fishman and Joseph Krajcik and Ronald Marx
Log on Education: K--12 and the Internet
Porter:2000:SCL
Tom Porter and Galyn Susman
On site: creating lifelike characters in Pixar movies
Simons:2000:PBB
Barbara Simons
From the President: building Big Brother
Konana:2000:IOI
Prabhudev Konana and Nirup M. Menon and Sridhar Balasubramanian
The implications of online investing
Gorriz:2000:EGC
Cecilia M. Gorriz and Claudia Medina
Engaging girls with computers through software games
Hargittai:2000:RLI
Eszter Hargittai
Radio's lessons for the Internet
Ackerman:2000:ROM
Mark S. Ackerman and Christine A. Hadverson
Reexamining organizational memory
And as far as overloading the == operator. I just followed what it says we are required to do in our instructions.