Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function that has two linked-list head pointers as parameters. Assume that the linked lists items are ordered by the < operator. On each

Write a function that has two linked-list head pointers as parameters. Assume that the linked lists items are ordered by the < operator. On each list, every item is less than the next item on the same list. The function should create a new linked list that contains all the items on both lists, and the new linked list should also be ordered (so that every item is less than the next item on the list). The new linked list should also eliminate duplicate items (i.e., if the same item appears on both input lists, then only one copy is placed in the newly constructed linked list). To eliminate duplicate items, you may assume that two items can be compared for equality using ==. The function should return a head pointer for the newly constructed linked list. Use node1.h as reference.

Node1.h:

namespace main_savitch_5 { 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; } // 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:  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; }; // FUNCTIONS for the linked list toolkit  std::size_t list_length(const node* head_ptr); void list_head_insert(node*& head_ptr, const node::value_type& entry); void list_insert(node* previous_ptr, const node::value_type& entry); node* list_search(node* head_ptr, const node::value_type& target); const node* list_search (const node* head_ptr, const node::value_type& target); node* list_locate(node* head_ptr, std::size_t position); const node* list_locate(const node* head_ptr, std::size_t position); void list_head_remove(node*& head_ptr); void list_remove(node* previous_ptr); void list_clear(node*& head_ptr); void list_copy(const node* source_ptr, node*& head_ptr, node*& tail_ptr); } #endif 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions