11597 - Copy a linked list (with friend)   

Description

Every node has

  • id
  • friend (a node inside the same linked list. The value may be NULL.)
  • next (to next node)

You are required to copy a linked list with same structure.

Input

The first line contains a non-negative integer N (1<=N<=100000). N represents how many node inside a linked list.

main function will create a linked list for you.

What you need to do is implement copy function in function.h.

Output

Copy the linked list.

Your copied linked list must have same structure as input.

 

Case 2 is designed for those who wants a challenge:

You will get Memory Limit Exceeded if using too much memory.

You will get Time Limit Exceeded if spending too much time iterating nodes from head.

You can pass the case 2 if you use another memory (e.g., Node *temp[100000];). However, this is not the correct answer.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11597.c

Partial Judge Header

11597.h

Tags




Discuss