Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ИнженерияЗнаний2
  8. {
  9.     class Tree
  10.     {
  11.         private class Node
  12.         {
  13.             public string text;
  14.             public Node parent;
  15.             public Node Yes;
  16.             public Node No;
  17.             public Node(string s)
  18.             {
  19.                 text = s;
  20.             }            
  21.         }
  22.         Node root;
  23.         Node itt;
  24.         public Tree(string s)
  25.         {
  26.             root = new Node(s);
  27.             itt = root;
  28.         }
  29.         public void SetYes(string s)
  30.         {
  31.             if (itt.Yes == null)
  32.                 itt.Yes = new Node(s)
  33.                 {
  34.                     parent = itt
  35.                 };
  36.             else itt.Yes.text = s;
  37.         }
  38.         public void SetNo(string s)
  39.         {
  40.             if (itt.No == null)
  41.                 itt.No = new Node(s)
  42.             {
  43.                 parent = itt
  44.             };
  45.  
  46.             else itt.No.text = s;
  47.         }
  48.         public void ToParent()
  49.         {
  50.             itt = itt.parent;
  51.         }
  52.         public void ToRoot()
  53.         {
  54.             itt = root;
  55.         }
  56.         public void SetText(string s)
  57.         {
  58.             itt.text = s;
  59.         }
  60.         public void ToYes()
  61.         {
  62.             itt = itt.Yes;
  63.         }
  64.         public void ToNo()
  65.         {
  66.             itt = itt.No;
  67.         }
  68.         public bool IsLeaf()
  69.         {
  70.             return itt.No == null && itt.Yes == null;
  71.         }
  72.         public bool IsRoot()
  73.         {
  74.             return itt.parent == null;
  75.         }
  76.         public string GetText()
  77.         {
  78.             return itt.text;
  79.         }
  80.         public void RemoveCurrent()
  81.         {
  82.             Node n = itt.parent;
  83.             itt = null;
  84.             itt = n;
  85.         }
  86.        
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement