按照要求补充实现Linked List的所有函数并通过测试,不能使用STL中现有的方法。
Here is a C++ class definition for an abstract data type LinkedList of strings. Implement each member function in the class below. Some of the functions we may have already done in lecture, thats fine, try to do those first without looking at your notes. You may add whatever private data members or private member functions you want to this class.
1 |
|
When we dont want a function to change a parameter representing a value of the type stored in the LinkedList, we pass that parameter by constant reference. Passing it by value would have been perfectly fine for this problem, but we chose the const reference alternative because that will be more suitable after we make some generalizations in a later problem.
The get function enables a client to iterate over all elements of a LinkedList. In other words, this code fragment
1 | LinkedList ls; |
must write
AgnesAgathaGermaineJack
The printList and printReverse functions enables a client to print elements of a LinkedList. In other words, this code fragment
1 | LinkedList ls; |
must write
Helen Lionel Louise GeorgeGeorge Louise Lionel Helen
You should have one space between after each item printed with an additional newline after the last item.
Here is an example of the append function:
1 | LinkedList e1; |
Here is an example of the reverseList function:
1 | LinkedList e1; |
Heres an example of the swap function:
1 | LinkedList e1; |
When comparing items, just use the == or != operators provided for the string type by the library. These do case-sensitive comparisons, and thats fine.
Turn it in
There will be a link on CCLE that will enable you to turn in this homework. Turn in one zip file that contains your solutions to the homework problem. The zip file must contain only the file linkedlist.cpp. The source file will contain all the code from the top of this specification (includes, typedef, struct Node, class LinkedList), a main routine and the LinkedList member functions you will write. If you dont finish everything you should return dummy values for your missing definitions. You can have the main routine do whatever you want, because we will rename it to something harmless, never call it, and append our own main routine to your file. Our main routine will thoroughly test your functions. Youll probably want your main routine to do the same. Your code must be such that if we insert it into a suitable test framework with a main routine and appropriate #include directives, it compiles. (In other words, it must have no missing semicolons, unbalanced parentheses, undeclared variables, etc.)