HEy i was just wondering if someone could look over my program and make any suggestions on what i could do better and if I have everything that was asked...here is what was assigned:
Write a C++ class template (named GenLookup) to implement a generic look-up list class. The elements of the lists may be instantiated to any simple data type or to string type. The lists must be implemented by a linked-list for which you keep a pointer to the start (Head) of the list. New items will always be added at the start of the list. {For efficiency and ease of maintenance, minimize the code by using a singly-linked list and only a Head pointer in the GenLookup class (or alternatively, in a List class it is based on).} The operations you must provide will be used as:
MyListl.Add(ElementVal); // add item to this list
MyList2.Remove( ElementVal); // get an item off this list
Element* Ptr = MyList2.Find( ElementVal); // get a pointer to an item on this list (or null if not found)
Write a driver program that will create multiple lists (including numeric and string types) and allow the user to add, remove, and find data on each, with output to show the operations performed and values added, removed, or found. Raise an exception when Remove is attempted on an item not on the list. Handle this exception in the driver program.
Hand in source listings for all classes and for the driver program, the executable file (.exe), and sample output that shows you have instantiated multiple lists with different kinds of elements (including string) and that you have verified the behaviors for each list.
Thanks for using code tags even though you somehow lost the formatting.
You could use initialization lists http://www.parashift.com/c++-faq-lit....html#faq-10.6 New nodes should be added at the start of the list and as I understand the text that's the head. If so, you can simplify the code a lot. Also, the current code is more a sorted insert than an add.
You still haven't written the find method and the ever so important testing code but before that, try to compile it as it is since you have some minor issues to solve. If you fail to solve them please ask again.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
1) Your class won't compile as listed here.
I'll assume you copied a list class called NumberList from somewhere and atempted to "templatize" it.
2) Your Add() function has an invalid prototype. There's a second opening '(' character.
guessing it's a transcription error and it's intended to be a reference mark.
3) Your Add() function doesn't work as prescribed in the task. It seems to be written to be adding a node to the end of the list rather than to the start.
Bookmarks