Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- List<T> List<T>::split(int splitPoint)
- {
- if (splitPoint > length)
- return List<T>();
- if (splitPoint < 0)
- splitPoint = 0;
- ListNode * secondHead = split(head, splitPoint);
- int oldLength = length;
- if (secondHead == head)
- {
- // current list is going to be empty
- head = NULL;
- tail = NULL;
- length = 0;
- }
- else
- {
- // set up current list
- tail = head;
- while (tail->next != NULL)
- tail = tail->next;
- length = splitPoint;
- }
- // set up the returned list
- List<T> ret;
- ret.head = secondHead;
- ret.tail = secondHead;
- if (ret.tail != NULL)
- {
- while (ret.tail->next != NULL)
- ret.tail = ret.tail->next;
- }
- ret.length = oldLength - splitPoint;
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement