public static void main(String[] args){ LinkedList myLinkedList = new LinkedList(); Scanner sn = new Scanner(System.in); System.out.println("How many numbers?"); int n = sn.nextInt(); System.out.println("Enter numbers"); while(n>0){ myLinkedList.addElement(sn.nextInt(),null); n--; } //Detect loop in linked list boolean hasLoop = myLinkedList.isLoopPresent(); if (hasLoop) { System.out.println("Yes it has a loop. Whoa!!!"); } else { System.out.println("No loop. Told you!"); } //Find length int length = myLinkedList.findLength(); System.out.println("Length of the linked list is " + length); //Find recursive Length int recursiveLength = myLinkedList.findRecursiveLength(myLinkedList.head); System.out.println("Length of the linked list via recursion method is " + recursiveLength); //Find element at a certain index System.out.println("Which place number you want to find"); int nth = sn.nextInt(); int nthElement = myLinkedList.findNthElement(nth); System.out.println("The nth element you wanted is "+ nthElement); //Find element from the end of a linked list. int nthElementFromTheBack = myLinkedList.findBackNthElement(nth); System.out.println("The reverse nth element you wanted is "+ nthElementFromTheBack); //Print the linked list System.out.println("The linked list consists of"); myLinkedList.printList(); //Reverse the linked list Node checkNode = myLinkedList.reverseList(myLinkedList.head); if(checkNode==null) System.out.println("No list exists"); else { System.out.println("Reversed List"); myLinkedList.printList(); } //DELETIONS //Delete a certain element from the linked list int data = 2; myLinkedList.deleteElement(data); System.out.println("The linked list after deletion consists of"); myLinkedList.printList(); //Delete head boolean isHeadDeleted = myLinkedList.deleteHead(); if(isHeadDeleted){ System.out.println("The linked list after deletion of head consists of"); myLinkedList.printList(); } else{ System.out.println("List was empty"); } //Delete the whole list boolean isDeleted = myLinkedList.deleteList(); if(isDeleted){ System.out.println("List deleted"); } else{ System.out.println("No list present"); } }