I recently made a linked list for myself, the code of which was posted here, if anyone would be interested. Now, as the next task, I had to make an Iterator
for my list, which is working properly.
I recently made a linked list for myself, the code of which was posted here, if anyone would be interested. Now, as the next task, I had to make an Iterator
for my list, which is working properly.
Self-Made Linked List Iteratormade linked list iterator
I recently made a linked list for myself, the code of which was posted here :
Self-Made Linked Listhere , if anyone would be interested. Now, as the next task, I had to make an IteratorIterator
for my list. It, which is working properly. Here is the code:
Here are the variables of the LinkedListLinkedList
class:
This is a Node Node<U>
:
And this is how I add a new NodeNode
:
Could this be made significantly faster? Does the code comply with the Java coding conventions? Note that I am a beginner. Thank you.
Self-Made Linked List Iterator
I recently made a linked list for myself, the code of which was posted here : Self-Made Linked List if anyone would be interested. Now, as the next task, I had to make an Iterator for my list. It is working properly. Here is the code:
Here are the variables of the LinkedList class:
This is a Node :
And this is how I add a new Node:
Could this be made significantly faster? Does the code comply with the Java coding conventions? Note that I am a beginner. Thank you.
Self-made linked list iterator
I recently made a linked list for myself, the code of which was posted here , if anyone would be interested. Now, as the next task, I had to make an Iterator
for my list, which is working properly.
Here are the variables of the LinkedList
class:
This is a Node<U>
:
And this is how I add a new Node
:
Could this be made significantly faster? Does the code comply with the Java coding conventions?
Here are the variables of the LinkedList class:
private Node<T> lastNode;
private Node<T> firstNode;
private int size;
This is a Node :
private static class Node<U>{
private Node<U> nextNode = null;
private Node<U> previousNode = null;
private int index;
private U data;
private Node(U data){
this.data = data;
}
}
And this is how I add a new Node:
public boolean add(T data) {
if (data == null) {
return false;
}
Node<T> currentNode = new Node<T>(data);
if (this.isEmpty()){
currentNode.previousNode = null;
currentNode.index = 0;
this.firstNode = currentNode;
} else {
currentNode.previousNode = lastNode;
lastNode.nextNode = currentNode;
currentNode.index = lastNode.index + 1;
}
this.lastNode = currentNode;
this.size++;
return true;
}
Could this be made significantly faster? Does the code comply with the Java coding conventions? Note that I am a beginner. Thank you.
Could this be made significantly faster? Does the code comply with the Java coding conventions? Note that I am a beginner. Thank you.
Here are the variables of the LinkedList class:
private Node<T> lastNode;
private Node<T> firstNode;
private int size;
This is a Node :
private static class Node<U>{
private Node<U> nextNode = null;
private Node<U> previousNode = null;
private int index;
private U data;
private Node(U data){
this.data = data;
}
}
And this is how I add a new Node:
public boolean add(T data) {
if (data == null) {
return false;
}
Node<T> currentNode = new Node<T>(data);
if (this.isEmpty()){
currentNode.previousNode = null;
currentNode.index = 0;
this.firstNode = currentNode;
} else {
currentNode.previousNode = lastNode;
lastNode.nextNode = currentNode;
currentNode.index = lastNode.index + 1;
}
this.lastNode = currentNode;
this.size++;
return true;
}
Could this be made significantly faster? Does the code comply with the Java coding conventions? Note that I am a beginner. Thank you.