Source of toVector.cpp


  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:    Node<ItemType>* curPtr = headPtr;
  9:    int counter = 0;
 10:         while ((curPtr != nullptr) && (counter < itemCount))
 11:    {
 12:                 bagContents.push_back(curPtr->getItem());
 13:       curPtr = curPtr->getNext();
 14:       counter++;
 15:    }  // end while
 16:    
 17:    return bagContents;
 18: }  // end toVector