solving Josephus problem with linked lists