Algorithms and Data Structures

Mix the Linked List

Given a queue of people represented as a Doubly Linked List, you are asked to mix the list in a specific way. You should bring the last person in the queue between the first and the second in the initial queue, the person before the last one, between the second and the third in the initial queue, etc.


The initial data for the linked list is obtained automatically. You don’t need to do anything.
People are represented with their names which consist of Latin letters only and don’t exceed length of 15.


The program should print the final linked list.


10 a b c d e f g h j k
a k b j c h d g e f
9 a b c d e f g h j
a j b h c g d f e
3 Alice Bob Anna
Alice Anna Bob


Time limit: 1 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue