Source of insert.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: // The public method insert:
  5: template<class ItemType>
  6: bool LinkedList<ItemType>::insert(int newPosition, const ItemType& newEntry)
  7: {
  8:    bool ableToInsert = (newPosition >= 1) && (newPosition <= itemCount + 1);
  9:    if (ableToInsert)
 10:    {
 11:       // Create a new node containing the new entry
 12:       Node<ItemType>* newNodePtr = new Node<ItemType>(newEntry);
 13:       headPtr = insertNode(newPosition, newNodePtr, headPtr);
 14:    } // end if
 15:    return ableToInsert;
 16: } // end insert