Exemple #1
0
vector<Type> SinglyLinkedList<Type>::convertToVector() {
  vector<Type> v;
  if (size == 0) return v;
  LinkedListNode<Type>* pLoc = head;
  while (pLoc->next != nullptr) {
    Efficiency::totalDataStructureOperations++;
    v.push_back(pLoc->getData());
    pLoc = pLoc->next;
  }
  Efficiency::totalDataStructureOperations++;
  v.push_back(pLoc->getData());
  return v;
}
Exemple #2
0
Type SinglyLinkedList<Type>::get(int key) {
  LinkedListNode<Type>* pLoc = head;
  while (pLoc != nullptr) {
    if (pLoc->getKey() == key) {
      Efficiency::totalDataStructureOperations++;
      return pLoc->getData();
    }
    Efficiency::totalDataStructureOperations++;
    pLoc = pLoc->next;
  }
  throw "not found";
}