class LinkedList { // create an object of Node class // represent the head of the linked list Node head; // static inner class static class Node { int value; // connect each node to next node Node next; Node[int d] { value = d; next = null; } } // check if loop is present public boolean checkLoop[] { // create two references at start of LinkedList Node first = head; Node second = head; while[first != null && first.next !=null] { // move first reference by 2 nodes first = first.next.next; // move second reference by 1 node second = second.next; // if two references meet // then there is a loop if[first == second] { return true; } } return false; } public static void main[String[] args] { // create an object of LinkedList LinkedList linkedList = new LinkedList[]; // assign values to each linked list node linkedList.head = new Node[1]; Node second = new Node[2]; Node third = new Node[3]; Node fourth = new Node[4]; // connect each node of linked list to next node linkedList.head.next = second; second.next = third; third.next = fourth; // make loop in LinkedList fourth.next = second; // printing node-value System.out.print["LinkedList: "]; int i = 1; while [i
Create linked list using for loop Java
Bài Viết Liên Quan
Toplist mới
#1
Top 7 download sách nói kinh doanh 2023
6 tháng trước#2
Top 8 bà bầu uống nước ép cà rốt tốt không 2023
6 tháng trước#4
Top 8 phrasal verb unit 4 lớp 9 2023
6 tháng trước#5
Top 7 ứng dung kỹ năng giao tiếp sư phạm 2023
6 tháng trước#6
Top 6 5 chú tiểu bồng lai la con của ai 2023
6 tháng trước#7
Top 10 khi chàng nhìn thẳng vào mắt bạn 2023
6 tháng trước#8
Top 4 đồ an tốt nghiệp thiết kế đồ họa văn lang 2023
6 tháng trước#9
Top 4 7 nụ cười xuân mùa 5 trực tiếp 2023
6 tháng trướcBài mới nhất
Chủ Đề
Hỏi Đáp
Toplist
Là gì
Địa Điểm Hay
Mẹo Hay
programming
Học Tốt
mẹo hay
Nghĩa của từ
Công Nghệ
Bao nhiêu
Khỏe Đẹp
đánh giá
Top List
bao nhiêu
bao nhieu
hướng dẫn
So Sánh
Bài tập
So sánh
Tiếng anh
Xây Đựng
Ngôn ngữ
Bài Tập
Sản phẩm tốt
Ở đâu
Thế nào
Dịch
Hướng dẫn
Đại học
Máy tính
Tại sao
Món Ngon
Khoa Học
Vì sao
Bao lâu
Hà Nội