File tree 1 file changed +36
-0
lines changed
Course 2 - Data Structures in JAVA/Lecture 8 - Linked Lists II
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -33,3 +33,39 @@ Sample Output 2 :
33
33
10
34
34
50 40 30 20 10
35
35
*/
36
+ /*
37
+
38
+ Following is the Node class already written for the Linked List
39
+
40
+ class LinkedListNode<T> {
41
+ T data;
42
+ LinkedListNode<T> next;
43
+
44
+ public LinkedListNode(T data) {
45
+ this.data = data;
46
+ }
47
+ }
48
+
49
+ */
50
+
51
+ public class Solution {
52
+
53
+ public static LinkedListNode<Integer> reverseLinkedListRec(LinkedListNode<Integer> head) {
54
+ //Your code goes here
55
+
56
+ if (head==null || head.next==null)
57
+ {
58
+ return head;
59
+ }
60
+ LinkedListNode<Integer> smallerHead=reverseLinkedListRec(head.next);
61
+ LinkedListNode<Integer> node=smallerHead;
62
+ while (node.next!=null)
63
+ {
64
+ node=node.next;
65
+ }
66
+ node.next=head;
67
+ head.next=null;
68
+ return smallerHead;
69
+ }
70
+
71
+ }
You can’t perform that action at this time.
0 commit comments