דילוג לתוכן

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


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

המחלקה 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();
    }
}

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

תגובות

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

  1. אנונימי
    תודה 3>
  2. אנונימי
    תודה >>>>>>
  3. אנונימי
    תודה >>>>>>
  4. אנונימי
    לא הבנתי למה צריך את זה? אלו פונקציות שלא צריך לממש בבגרות
    1. אנונימי
      זה המימוש מאחורי הקלעים של המחלקות. צריך להוסיף אותן אם משתמשים בהן במחשב למשל. הן מועילות כי אתה יודע מה ממומש לך ועומד לרשותך בבגרות
  5. אנונימי
    אלוף
  6. אנונימי
    סקיבידי ריז מאוהיו קיבל סיגמה באן כי יש לו ריז מסקיבידי סיטי
  7. אנונימי
    שמע שיש לי ריז
  8. אנונימי
    כה אה יא גבגבר תודה דרך אגב אחלה קוד יא גבר
  9. אנונימי
    טונג טונג טונג טונג טונג טונג טונג טונג סהור
  10. אנונימי
    מישהו רוצה להיות חבר שלי
  11. אנונימי
    אני רוצה! UwU
  12. אנונימי
    אומייגדדד איזה ריזלרררר
    1. אנונימי
      בייבי גירל
  13. אנונימי
    Trump is the best president
  14. אנונימי
    Trump 2028! MAGA!
  15. skibidi
    טונג טונג טונג סהור

בודק את מצב ההתחברות…