Skip to content

Instantly share code, notes, and snippets.

@YonLiud
Last active February 21, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonLiud/649c8e2c3ceeb06ca645a2d370bc0ae2 to your computer and use it in GitHub Desktop.
Save YonLiud/649c8e2c3ceeb06ca645a2d370bc0ae2 to your computer and use it in GitHub Desktop.
Node<T> Class made for highschool & education
/* The class Node<T> **/
public class Node<T>
{
private T value; // Node value
private Node<T> next; // next Node
/* Constructor - returns a Node with "value" as value and without successesor Node **/
public Node(T value)
{
this.value = value;
this.next = null;
}
/* Constructor - returns a Node with "value" as value and its successesor is "next" **/
public Node(T value, Node<T> next)
{
this.value = value;
this.next = next;
}
/* Returns the Node "value" **/
public T GetValue()
{
return this.value;
}
/* Returns the Node "next" Node **/
public Node<T> GetNext()
{
return this.next;
}
/* Return if the current Node Has successor **/
public bool HasNext()
{
return (this.next != null);
}
/* Set the value attribute to be "value" **/
public void SetValue(T value)
{
this.value = value;
}
/* Set the next attribute to be "next" **/
public void SetNext(Node<T> next)
{
this.next = next;
}
/* Returns a string that describes the Node (and its' successesors **/
public override string ToString()
{
return value + " --> " + next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment