כל מבני הנתונים של משרד החינוך (node , binnode , queue , stack) בC#


מבני הנתונים של משרד החינוך

page icon

המחלקה Node<T> - חוליה.

class Node<T>
{
    private T value;
    private Node<T> next;
    public Node(T value)
    {
        this.value = value;
        this.next = null;
    }
    public Node(T value, Node<T> next)
    {
        this.value = value;
        this.next = next;
    }
    public T GetValue()
    {
        return this.value;
    }
    public Node<T> GetNext()
    {
        return this.next;
    }
    public bool HasNext()
    {
        return this.GetNext() != null;
    }
    public void SetValue(T value)
    {
        this.value = value;
    }
    public void SetNext(Node<T> next)
    {
        this.next = next;
    }
    public override string ToString()
    {
        Node<T> pos = this;
        string str = "[";
        while (pos.HasNext())
        {
            str += pos.value + ",";
            pos = pos.next;
        }
        str += pos.value + "]";
        return str;
    }
}

המחלקה Stack<T> - מחסנית.

class Stack<T>
{
    private Node<T> first;
    public Stack()
    {
         this.first = null;
    }
    public bool IsEmpty()
    {
         return this.first == null;
    }
    public void Push(T x)
    {
         this.first = new Node<T>(x, this.first);
    }
    public T Top()
    {
         return this.first.GetValue();
    }
    public T Pop()
    {
         T x = this.first.GetValue();
         this.first = this.first.GetNext();
         return x;
    }
    public override string ToString()
    {
         string str = "[";
         Node<T> pos = this.first;
         while (pos != null)
         {
              str = str + pos.GetValue().ToString();
              if (pos.HasNext())
              str = str + ",";
              pos = pos.GetNext();
         }
         str = str + "]";
         return str;
    }
}

המחלקה Queue<T> - תור.

class Queue<T>
{
    private Node<T> first;
    private Node<T> last;
    public Queue()
    {
         this.first = null;
         this.last = null;
    }
    public void Insert(T value)
    {
         Node<T> newNode = new Node<T>(value);
         if (this.first == null)
              this.first = newNode;
         else
              this.last.SetNext(newNode);
         this.last = newNode;
    }
    public T Remove()
    {
         T value = this.first.GetValue();
         this.first = this.first.GetNext();
         if (this.first == null)
              this.last = null;
         return value;
    }
    public T Head()
    {
         return this.first.GetValue();
    }
    public bool IsEmpty()
    {
         return this.first == null;
    }
    public override string ToString()
    {
         return "" + this.first;
    }
}

המחלקה BinNode<T> - צומת.

class BinNode<T>
{
    private BinNode<T> left;
    private T value;
    private BinNode<T> right;
    public BinNode(T value)
    {
         this.left = null;
         this.value = value;
         this.right = null;
    }
    public BinNode(BinNode<T> left, T value, BinNode<T> right)
    {
         this.left = left;
         this.value = value;
         this.right = right;
    }
    public T GetValue()
    {
         return this.value;
    }
    public BinNode<T> GetLeft()
    {
         return this.left;
    }
    public BinNode<T> GetRight()
    {
         return this.right;
    }
    public void Setvalue(T value)
    {
         this.value = value;
    }
    public void SetLeft(BinNode<T> left)
    {
         this.left = left;
    }
    public void SetRight(BinNode<T> right)
    {
         this.right = right;
    }
    public bool HasLeft()
    {
         return this.left != null;
    }
    public bool HasRight()
    {
         return this.right != null;
    }
    public override string ToString()
    {
         return this.value.ToString();
    }
}

מתקדמים מהר מהכיתה? מצורף מדריך סי שארפ מתקדם שכתבתי המלמד תכנות ברמה של התעשייה אותו כתבתי להכשרת ג'וניורים בחברת הייטק שעבדתי בה - לינק.




17 תגובות:

  1. לא הבנתי למה צריך את זה? אלו פונקציות שלא צריך לממש בבגרות

    השבמחק
    תשובות
    1. זה המימוש מאחורי הקלעים של המחלקות. צריך להוסיף אותן אם משתמשים בהן במחשב למשל. הן מועילות כי אתה יודע מה ממומש לך ועומד לרשותך בבגרות

      מחק
  2. סקיבידי ריז מאוהיו קיבל סיגמה באן כי יש לו ריז מסקיבידי סיטי

    השבמחק
  3. שמע שיש לי ריז

    השבמחק
  4. כה אה יא גבגבר
    תודה דרך אגב אחלה קוד יא גבר

    השבמחק
  5. טונג טונג טונג טונג טונג טונג טונג טונג סהור

    השבמחק
  6. מישהו רוצה להיות חבר שלי

    השבמחק
  7. אני רוצה! UwU

    השבמחק
  8. אומייגדדד איזה ריזלרררר

    השבמחק
  9. Trump is the best president

    השבמחק
  10. טונג טונג טונג סהור

    השבמחק

"הבעיה הגדולה ביותר בתקשורת היא האשליה שהיא התקיימה" - ג'ורג' ברנרד שו.