Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename T>
- typename BidiLinkedList<T>::Node**
- BidiLinkedList<T>::findAll(Node* startFrom, const T& val, int& size)
- {
- if (!startFrom)
- return nullptr;
- // try not to use any standard containers. create an array only when found a first occurence
- Node** res = nullptr;
- size = 0;
- Node *current = startFrom;
- // figuring out the size of the container
- while (current)
- {
- if (current->getValue() == val)
- size++;
- current = current->getNext();
- }
- current = startFrom;
- // if there are no suitable elements, return null
- if (size != 0)
- res = new Node*[size];
- else return res;
- // going through the list for the second time
- // this time filling in the array
- int i = 0;
- while (current)
- {
- if (current->getValue() == val)
- res[i++] = current;
- current = current->getNext();
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement