Skip to main content
added 17 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237
  1. Your are creating something similar to java.util.LinkedListjava.util.LinkedList, thus it is best practice to use same or similar method names.

  2. Your list is sorted. Whenever you search for an element, change this loop:

    while (tmpNode != null && tmpNode.data != d) { tmpNode = tmpNode.next; }

     while (tmpNode != null && tmpNode.data != d) {
         tmpNode = tmpNode.next;
     }
    
     if (tmpNode == null) {
         System.out.println("That node does not exist in the list");
         return;
     }
    

to this:

    while (tmpNode != null && tmpNode.data < d) {
        tmpNode = tmpNode.next;
    }

    if (tmpNode == null|| tmpNode.data != d) {
        System.out.println("That node does not exist in the list");
        return;
    }

It stops, whenever the element can't be found.

  1. Instead of System.out.printlnSystem.out.println, use a booleanboolean return value to indicate success.
  1. Your are creating something similar to java.util.LinkedList, thus it is best practice to use same or similar method names.

  2. Your list is sorted. Whenever you search for an element, change this loop:

    while (tmpNode != null && tmpNode.data != d) { tmpNode = tmpNode.next; }

     if (tmpNode == null) {
         System.out.println("That node does not exist in the list");
         return;
     }
    

to this:

while (tmpNode != null && tmpNode.data < d) {
        tmpNode = tmpNode.next;
    }

    if (tmpNode == null|| tmpNode.data != d) {
        System.out.println("That node does not exist in the list");
        return;
    }

It stops, whenever the element can't be found.

  1. Instead of System.out.println, use a boolean return value to indicate success.
  1. Your are creating something similar to java.util.LinkedList, thus it is best practice to use same or similar method names.

  2. Your list is sorted. Whenever you search for an element, change this loop:

     while (tmpNode != null && tmpNode.data != d) {
         tmpNode = tmpNode.next;
     }
    
     if (tmpNode == null) {
         System.out.println("That node does not exist in the list");
         return;
     }
    

to this:

    while (tmpNode != null && tmpNode.data < d) {
        tmpNode = tmpNode.next;
    }

    if (tmpNode == null|| tmpNode.data != d) {
        System.out.println("That node does not exist in the list");
        return;
    }

It stops whenever the element can't be found.

  1. Instead of System.out.println, use a boolean return value to indicate success.
Source Link
Daniel
  • 291
  • 1
  • 5

  1. Your are creating something similar to java.util.LinkedList, thus it is best practice to use same or similar method names.

  2. Your list is sorted. Whenever you search for an element, change this loop:

    while (tmpNode != null && tmpNode.data != d) { tmpNode = tmpNode.next; }

     if (tmpNode == null) {
         System.out.println("That node does not exist in the list");
         return;
     }
    

to this:

while (tmpNode != null && tmpNode.data < d) {
        tmpNode = tmpNode.next;
    }

    if (tmpNode == null|| tmpNode.data != d) {
        System.out.println("That node does not exist in the list");
        return;
    }

It stops, whenever the element can't be found.

  1. Instead of System.out.println, use a boolean return value to indicate success.