c++
You are given the ListNode and the LinkList
classes. You are to extend the LinkList class to include
a copy constructor, an overloaded assignment operator, and a “sort”
function that can be a selection sort, a merge sort, or you can
make a copy of each node and insert in in place in a new sorted
link list. Using one from the internet is acceptable.
The copy constructor and assignment overload must implement deep
copies.
You are also to create a main driver program that reads in a
sequence of commands from a file. Example files are
given below.
You must parse the file using c-style strings. You
may not include the <string> class or use the string class in
any way. You must implement the entire program using
c-style strings. You may use helper functions such as
strlen, strcpy, atoi, etc.
Hint:
You may find it useful to create some c-style string helper
functions in your main driver. Tackle the string parsing
and command structure before jumping
into the link lists.
Example Files
There are 7 possible commands.
They are CREATE, PUSH_BACK, REMOVE_AT, DISPLAY, SET, SORT and
CLEAR.
CREATE has two possibilities:
Example 1: [CREATE LIST 0] will create a new empty
link list with numerical identifier 0.
Example 2: [CREATE LIST 1 FROM 0] will create a new
link list with numerical identifier 1 by copying the values from
the link list with numerical identifier 0. A deep copy
will be performed.
You may assume there will only exist, at most, link lists with
numerical identifiers 0 through 9.
PUSH_BACK:
Example: [PUSH_BACK LIST 0 123] will push the value
123 to the tail of the link list 0.
REMOVE_AT:
Example: [REMOVE_AT LIST 0 2] will remove the 2 index
(the third element) from link list 0.
DISPLAY:
Example: [DISPLAY LIST 0] will display the contents
of link list 0.
SET:
Example: [SET LIST 0 EQ LIST 1] will set the contents
of list 0 equal to the contents of list 1. A deep copy
will be performed.
SORT:
Example: [SORT LIST 0] will sort the elements of list
0.
CLEAR:
Example: [CLEAR LIST 0] will empty link list 0 and
free any allocated memory.
Example File 1
CREATE LIST 0
PUSH_BACK LIST 0 123
PUSH_BACK LIST 0 234
PUSH_BACK LIST 0 345
REMOVE_AT LIST 0 1
DISPLAY LIST 0
Sample Output:
CREATE LIST 0
PUSH_BACK LIST 0 123
PUSH_BACK LIST 0 234
PUSH_BACK LIST 0 345
REMOVE_AT LIST 0 1
DISPLAY LIST 0
Index: 0 Value: 123
Index: 1 Value: 345
linklist.cpp
linklist.h
ListNode.cpp
ListNode.h
*********Create main.cpp**********
c++ You are given the ListNode and the LinkList classes. You are to extend the LinkList class to include a copy constru
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
c++ You are given the ListNode and the LinkList classes. You are to extend the LinkList class to include a copy constru
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!