public class CircularLinkedlistinsert {
private Node first;
private static class Node {
int element;
Node next;
public Node(int element, Node next) {
this.element = element;
this.next = next;
}
}
public void insertNodeInCircularLL(int element) {
Node node = new Node(element, null);
if (first == null) {
first = node;
first.next = first;
} else {
Node current = first;
do {
if (((current.element <= element) && (current.next.element >= element)) || current.next == first) {
node.next = current.next;
current.next = node;
if (element < first.element) {
first = node;
}
return;
}
current = current.next;
} while (current != first);
}
}
}
}
|
|||||
|
Class names should have the first letter of each word capitalized. I'd also change the name to remove the activity and just describe the object. i.e.,
While it doesn't matter too much since this is a
Again, I'd rename this method for style points. Since the entire class is a The problem with the rest of the implementation, to me, is that you are using the It looks like, based on this if statement ( I think you need to have the Two more advanced notes from this:
|
|||
|