- The node class is defined as follows:
- class node {
- public: // TYPEDEF
- typedef double value_type;
- // CONSTRUCTOR
- node(const value_type& init_data = value_type(), node* init_link = NULL) {
- data_field = init_data; link_field = init_link; } 9.
- // Member functions to set the data and link fields:
- void set_data(const value_type& new_data) { data_field = new_data; } void set_link(node* new_link) { link_field = new_link; }
- // Constant member function to retrieve the current data: 15. value_type data() const { return data_field; }
- // Two slightly different member functions to retreive the current link:
- const node* link() const { return link_field; } node* link() { return link_field; }
- private:
- value_type data_field;
- node* link_field;
- };
Implement the following function. (Note: No toolkit function is available. Only the node class is available.)
- void list_copy (const node* source_ptr, node*& head_ptr, node*& tail_ptr) 2. // Precondition: source_ptr is the head pointer of a linked list.
- // Postcondition: head_ptr and tail_ptr are the head and tail pointers for a new list that
- // contains the same items as the list pointed to by source_ptr
- {
- Please justify why the linked list toolkit functions are not member functions of the node class?
- In the following function, why cursor has been declared as a const variable? What happens if you change it to a non-const variable?
- size_t list_length (const node* head_ptr)
- // Precondition: head_ptr is the head pointer of a linked list.
- // Postcondition: The value returned is the number of nodes in the // linked list.
- {
- const node* cursor;
- size_t answer;
- answer = 0;
- for (cursor = head_ptr; cursor != NULL; cursor = cursor > link())
- ++answer;
- return answer;
- }
- We are interested in implemented the back and forward arrow functionality in a mobile app. When back arrow is touched, the previous screen is shown, and when forward arrow is pressed (if applicable), then the forward screen is shown. Please justify what type of data structure you would use.
- Why does our node class have two versions of the link member function?
- One is public, the other is private.
- One is to use with a const pointer, the other with a regular pointer.
- One returns the forward link, the other returns the backward link.
- One returns the data, the other returns a pointer to the next node.
- What are the iterator invalidation rules for a data structure that stores items in a linked list?
- What are the iterator invalidation rules for STLs vector class?
- What are the features of a random access iterator? Present the name of two STL data structures that offer random access iterators.
- The bag class is defined as follows:
- This class implements the following functions to create iterators:
- Please complete the implementation of the following iterator:
Reviews
There are no reviews yet.