Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85680b3

Browse files
author
Ram swaroop
committed
reverse alternate nodes and append at end: comments added
1 parent 4eaddaf commit 85680b3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/me/ramswaroop/linkedlists/ReverseAlternateNodesAndAppendAtEnd.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@
1212
*/
1313
public class ReverseAlternateNodesAndAppendAtEnd {
1414

15+
/**
16+
* Reverse alternate nodes and append them to end of the list.
17+
*
18+
* Example,
19+
*
20+
* Input List: 1->2->3->4->5->6
21+
* Output List: 1->3->5->6->4->2
22+
*
23+
* Input List: 12->14->16->18->20
24+
* Output List: 12->16->20->18->14
25+
*
26+
* @param node
27+
* @param <E>
28+
* @return
29+
*/
1530
public static <E extends Comparable<E>> SingleLinkedNode<E> reverseAlternateNodesAndAppendAtEnd(SingleLinkedNode<E> node) {
1631
SingleLinkedNode<E> curr = node, end = node, currNext, endNext;
1732

0 commit comments

Comments
 (0)