Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Tree Node Sample
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public abstract class TreeNode<T> { public T State { get; set; } public TreeNode<T> Parent; public int Cost { get; set; } public int Depth { get; set; } public int F { get; set; } protected void SetState (T state) { this.State = state; } protected void InitFirstNode () { this.Cost = 0; this.Depth = 0; } public abstract bool CompareTo (TreeNode<T> obj); public abstract bool CompareTo (T state); } public class SlidingPuzzleNode : TreeNode<int> { public SlidingPuzzleNode (int state) { SetState(state); InitFirstNode(); } private void CalculateStatus (SlidingPuzzleNode parent) { this.Cost = parent.Cost + 1; this.Depth = parent.Depth + 1; } public SlidingPuzzleNode (int state, SlidingPuzzleNode parent) { SetState(state); CalculateStatus(parent); } public override bool CompareTo (TreeNode<int> obj) { return CompareTo(obj.State); } public override bool CompareTo (int state) { return this.State == state; } } public class Program { public static void Main(string[] args) { var a = 90; var x = new SlidingPuzzleNode(a); var y = new SlidingPuzzleNode(a + 1, x); Console.WriteLine(y.CompareTo(x)); } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Main4-5
Sum of numbers in string
WATCH! Malignant (2021) Online Movie Full HD For Free Download
SpiltStringBetweenSpecialCharacters
New House Exam 11 April
newMultQ working on more2
Hello World
test
Recursive 2
R
Please log in to post a comment.