Question
This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to LinkedBag.cpp. Node.hpp/cpp should be fine
This is a c++ class utilizing class templates and linked lists. I need to implement the following member function(s) to LinkedBag.cpp. Node.hpp/cpp should be fine but if you feel like there needs to be a change for compilation or testing, feel free to do so but make sure to comment on why it was done.
/** @param a_bag whose contents are to be copied to this (the calling) bag @post this (the calling) bag has same contents as a_bag */
void operator= (const LinkedBag
Node.hpp
----------------------------------------------- /** @file Node.h Listing 4-1 */ #ifndef NODE_ #define NODE_
template
private: T item_; // A data item_ Node
//#include "Node.cpp" //Unsure if this should be included or not #endif -----------------------------------------------
Node.cpp
-----------------------------------------------
#include "Node.hpp" //#include
template
template
template
template
template
template
template
-----------------------------------------------
LinkedBag.hpp
-----------------------------------------------
/** ADT bag: Link-based implementation. @file LinkedBag.h Listing 4-3 */ #ifndef LINKED_BAG_ #define LINKED_BAG_
#include
template
private: Node
/** @return Returns either a pointer to the node containing a given entry or the null pointer if the entry is not in the bag. */ Node
}; // end LinkedBag
//#include "LinkedBag.cpp" //Unsure if this should be included or not #endif -----------------------------------------------
LinkedBag.hpp
-----------------------------------------------
#include "LinkedBag.hpp" #include "Node.hpp" #include
template
template
if (orig_chain_ptr == nullptr) head_ptr_ = nullptr; // Original bag is empty else { // Copy first node head_ptr_ = new Node
// Copy remaining nodes Node
while (orig_chain_ptr != nullptr) { // Get next item from original chain T next_item = orig_chain_ptr->getItem();
// Create a new node containing the next item Node
// Link new node to end of new chain new_chain_ptr->setNext(new_node_ptr);
// Advance pointer to new last node new_chain_ptr = new_chain_ptr->getNext();
// Advance original-chain pointer orig_chain_ptr = orig_chain_ptr->getNext(); } // end while
new_chain_ptr->setNext(nullptr); // Flag end of chain } // end if } // end copy constructor
template
template
template
template
head_ptr_ = next_node_ptr; // New node is now first node item_count_++;
return true; } // end add
template
return bag_contents; } // end toVector
template
// Delete first node Node
// Return node to the system node_to_delete->setNext(nullptr); delete node_to_delete; node_to_delete = nullptr;
item_count_--; } // end if
return can_remove; } // end remove
template
// Return node to the system node_to_delete->setNext(nullptr); delete node_to_delete;
node_to_delete = head_ptr_; } // end while // head_ptr_ is nullptr; node_to_delete is nullptr
item_count_ = 0; } // end clear
template
counter++; cur_ptr = cur_ptr->getNext(); } // end while
return frequency; } // end getFrequencyOf
template
// private
/** @return Returns either a pointer to the node containing a given entry or the null pointer if the entry is not in the bag. */ template
while (!found && (cur_ptr != nullptr)) { if (an_entry == cur_ptr->getItem()) found = true; else cur_ptr = cur_ptr->getNext(); } // end while
return cur_ptr; } // end getPointerTo
-----------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started