1: // Created by Frank M. Carrano and Timothy M. Henry. 2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. 4: template<class ItemType> 5: std::vector<ItemType> LinkedBag<ItemType>::toVector() const 6: { 7: std::vector<ItemType> bagContents; 8: fillVector(bagContents, headPtr); 9: return bagContents; 10: } // end toVector 12: template<class ItemType> 13: void LinkedBag<ItemType>::fillVector(vector<ItemType>& bagContents, 14: Node<ItemType>* curPtr) const 15: { 16: if (curPtr != nullptr) 17: { 18: bagContents.push_back(curPtr->getItem()); 19: fillVector(bagContents, curPtr->getNext()); 20: } // end if 21: } // end fillVector