Skip to content

Commit 6e1664a

Browse files
Added Single Linked List, Doubly Linked List, and Tortoise and Hare algorithms
1 parent f0fb971 commit 6e1664a

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/main/java/com/thealgorithms/LinkedList/DoublyLinkedLIst.java

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class SinglyLinkedList {
2+
class Node {
3+
int data;
4+
Node next;
5+
Node(int d) { data = d; next = null; }
6+
}
7+
8+
private Node head;
9+
10+
public void insertAtEnd(int data) {
11+
Node newNode = new Node(data);
12+
if (head == null) {
13+
head = newNode;
14+
return;
15+
}
16+
Node curr = head;
17+
while (curr.next != null) curr = curr.next;
18+
curr.next = newNode;
19+
}
20+
21+
public void display() {
22+
Node curr = head;
23+
while (curr != null) {
24+
System.out.print(curr.data + " -> ");
25+
curr = curr.next;
26+
}
27+
System.out.println("null");
28+
}
29+
}

src/main/java/com/thealgorithms/LinkedList/Tortoise_and_harealgo.java

Whitespace-only changes.

0 commit comments

Comments
 (0)