Given a linked list, reverse alternate nodes and append at the end

Given a linked list, reverse alternate nodes and append at the end

  • Given a linked list,performs the following task
    • Remove alternative nodes from second node
    • Reverse the removed list.
    • Append the removed list at the end
  • Example:
    • Input List: 1->2->3->4->5->6
    • After step 1 Linked list are 1>3->5 and 2->4->6
    • After step 2 Linked list are 1->3->5 abd 6->4->2
    • After step 3 Linked List is 1->3->5->6->4->2
    • Output List: 1->3->5->6->4->2
  • Algorithm
    • Remove alternate node
    • Reverse the second list {@link ReorderList}
    • For appending move to list1 to end and at end of list1 add the head of list 2

Latest Source Code:
Github: ListRemoveAlternativeAndAppend.java


Output:

1 2 3 4 5 6 
1 3 5 6 4 2 

Author: Hrishikesh Mishra