PrintNumberedList: prints the contents of the linked list to the screen in the format #: followed by a newline Print: prints the contents of the linked list to the screen separated by a blank space =: compares this list to see if it contains the same data, in the same order as another list. OffEnd: returns whether the iterator is off the end of the list, i.e. GetIterator: returns the element currently pointed at by the iterator GetSize: returns the current size of the list IsEmpty: tests whether the linked list is empty GetStop: returns the data of the last element GetStart: returns the data of the first element ReverseIterator: moves the iterator down by one node towards start InsertIterator: inserts an element after the node currently pointed to by the iteratorĪdvanceIterator: moves the iterator up by one node towards stop PointIterator: moves the iterator to the start of the listĭeleteIterator: removes the element currently pointed to by the iterator. InsertStop: inserts an element at the end of the list InsertStart: inserts an element at the beginning of the linked list RemoveStop: removes the element at the end of the list RemoveStart: removes the element at the beginning of the list In addition, you must add some additional functions to your List class.Īll of the required functions are described below:Ĭonstructor: constructs a new linked list object.Ĭopy constructor: makes a copy of the list objectĭestructor: frees the memory associated with the linked list Your doubly-linked list needs to be able to perform all of the same operations as your singly linked list. Part 3: Adding New Functions to your List If you want more information on doubly-linked lists, you can watch this short video (4.5 min). Important! Each time you update one of your functions, run your tests again to make sure your list is still working properly. Most of these updates are as simple as adding one line of code per function.įor example, let's look at the insertStart operation: To account for the presence of this additional pointer, you will need to make updates to your code for many of the list operations. The advantage of the previousnode pointer is the ease with which we can traverse the list in both directions. Therefore, your inner Node struct will look like the following:Īdditionally, bear in mind that the start Node of the list now has a linkprevious Node pointer to NULL while the stop Node has a linknext Node pointer to NULL. You can visualize a doubly-linked list likes so: The principle difference between the singly-linked list that you wrote in class and a doubly-linked list is that each node contains a pointer both to the next node and to the previous node in the list. The next part of the assignment is to alter the list that you wrote in class and lab to be a doubly-linked list. Once you are sure it is still working properly, try testing your list with different types of data.įor example, make Lists of strings, doubles, chars. Step 7: Compile and run your code again and verify that it is now working. You can leave List.cpp as an empty file or simply comment out the contents of this file. Now, you should have only two functional files: List.h and ListTest.cpp Note that libraries and namespace should go at the top of this file, not right here copy and paste all of the functions from List.cpp here Step 5: Inside of ListTest.cpp, alter any calls to your List constructor to specify that the list contains ints, by placing the word int inside of the. Step 4: Now, build your List.cpp file and correct any errors that the compiler is giving you. Here is an example of how to alter one of these functions: In other words:įor EACH of these functions, you will need to template them.Īlso you may need to change the type of data that they return or take in as a parameter so that it is generic. Step 3: Alter the functions inside your List.cpp file that you wrote for Lab 1 to match the prototypes in the List header file. Note that you will not need to alter functions like getSize which always should return an int. Listdata getStart() //this function now returns generic dataĪlter ALL remaining functions prototypes inside your List.h to work with generic listdata, as show above.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |