Skip to content

Commit

Permalink
Merge pull request #380 from katarinaking/820
Browse files Browse the repository at this point in the history
MNEMONIC-820: Enhanced Node Class
  • Loading branch information
katarinaking authored Mar 16, 2024
2 parents 2bc272f + 9bb0872 commit 719c075
Showing 1 changed file with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,62 @@

package org.apache.mnemonic.bench;

/**
* Represents a node in a linked list.
*
* @param <T> the type of data stored in the node
*/
public class Node<T> {

T data;
Node<T> nextNode;

public Node(T data) {
this.data = data;
this.nextNode = null;
}

public Node(T data, Node<T> node) {
this.data = data;
this.nextNode = node;
}

public T getData() {
return this.data;
}

public void setNext(Node<T> node) {
this.nextNode = node;
}

public Node<T> getNext() {
return this.nextNode;
}
private T data; // The data stored in the node
private Node<T> nextNode; // Reference to the next node in the list

/**
* Constructs a new node with the given data.
*
* @param data the data to be stored in the node
*/
public Node(T data) {
this.data = data;
this.nextNode = null;
}

/**
* Constructs a new node with the given data and reference to the next node.
*
* @param data the data to be stored in the node
* @param nextNode the next node in the list
*/
public Node(T data, Node<T> nextNode) {
this.data = data;
this.nextNode = nextNode;
}

/**
* Gets the data stored in the node.
*
* @return the data stored in the node
*/
public T getData() {
return this.data;
}

/**
* Sets the reference to the next node.
*
* @param nextNode the next node in the list
*/
public void setNext(Node<T> nextNode) {
this.nextNode = nextNode;
}

/**
* Gets the next node in the list.
*
* @return the next node in the list
*/
public Node<T> getNext() {
return this.nextNode;
}
}

0 comments on commit 719c075

Please sign in to comment.