Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry excluding="Java/LeetCode/October Leetcoding Challenge/|Java/|Java/Sets/" kind="src" path=""/>
<classpathentry excluding="LeetCode/October Leetcoding Challenge/|Sets/" kind="src" path="Java"/>
<classpathentry kind="src" path="Java/LeetCode/October Leetcoding Challenge"/>
<classpathentry kind="src" path="Java/Sets"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Snippets</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
71 changes: 71 additions & 0 deletions Java/ReversedLinkedList__arnauvila33.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@


public class ReversedLinkedList__arnauvila33 {

static Node head;

static class Node{
int data;
public Node next;
Node(int data){
this.data=data;
next=null;
}
}

/**
* Recursive method to reverse a Linked List.
* @param node The head node of the linked list.
* @return the inversed linked list.
*/
private static Node reverseList(Node node) {
if (node == null || node.next == null)
return node;


Node rest = reverseList(node.next);
node.next.next = node;


node.next = null;


return rest;
}

/**
* Method to print the list passed.
* @param head the head of the list to print.
*/
private static void print(Node head) {
Node temp = head;
while (temp != null) {
System.out.print(temp.data + " ");
temp = temp.next;
}
System.out.println();
}

/**
* Main method to test the reversedList method.
* @param args argument passed.
*/
public static void main(String[] args) {
ReversedLinkedList__arnauvila33 list=new ReversedLinkedList__arnauvila33();
list.head=new Node(15);
list.head.next = new Node(50);
list.head.next.next = new Node(100);
list.head.next.next.next = new Node(300);

System.out.print("Linked List: ");
list.print(list.head);

//Reversing the list
list.head = list.reverseList(list.head);

System.out.println("");
System.out.print("Linked List Reversed: ");
list.print(list.head);

}
}