Last active
February 21, 2021 14:59
-
-
Save YonLiud/649c8e2c3ceeb06ca645a2d370bc0ae2 to your computer and use it in GitHub Desktop.
Node<T> Class made for highschool & education
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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