13863 - Linked List Mergence - C++ Ver.   

Description

You might remember that we had a problem to merge two sorted linked lists at the beginning of the semester. Now we've learnt C++ ans thus the problem evolved a bit: templates, operator overloading are introduced, and we also micmic the behaviour of containers and iterators.

We declare the linked_list class with template, which has 2 member types (nested structs / classes), node & iterator.  The former is for our private internal design purposes only, whereas the latter is public to others.

Most of the member functions have been done. You only need implement 3 ones: dereference iterators, forward iterators and merge two sorted linked lists. Make sure to read the instructions in the header carefully.

 

Input

// Dereference the iterator
template <typename T>
T &linked_list<T>::iterator::operator*();

No parameter. The function would be called when *itr.

// Forward the itarator by pre-increment
template <typename T>
typename linked_list<T>::iterator linked_list<T>::iterator::operator++();

No parameter, too. The function would be called when ++itr.

// Merge two sorted list internally
template <typename T>
typename linked_list<T>::node *linked_list<T>::merge(node *, node *);

The 2 parameters are the head of 2 sorted linked list.

It's guarantees that the sum of the total length of the linked list is less than 200000.

Output

For the dereference operator of iterator, you should return the reference to which the iterator / node point to.

As for the pre-increment operator of iterator, you should forward that iterator and return the iterator itself.

Lastly, for the merge method of linked list, you should return the head of the merged list. Linear time complexity is expected .

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13863.cpp

Partial Judge Header

13863.h

Tags




Discuss