コード例 #1
0
 /// <summary>
 /// Check if the queue is empty. If yes, add a new node with the value to the queue front and assign queue back to be queue front since there is only one node.
 /// If the queue is not empty, create a new node with the value and assign the queue back to be the new node. Then add the queue count by 1.
 /// </summary>
 /// <param name="value"></param>
 public int Enqueue(int value)
 {
     if (this.front == null)
     {
         this.front = new Node2(value);
         this.back  = this.front;
     }
     else
     {
         Node2 newNode = new Node2(value, this.back);
         this.back = newNode;
     }
     this.count++;
     return(count);
 }
コード例 #2
0
 /// <summary>
 /// This constructor initiates a node with a given value and a link that points to a different value that is not null.
 /// </summary>
 /// <param name="value"></param>
 public Node2(int value, Node2 previous)
 {
     this.Value    = value;
     this.Next     = null;
     previous.Next = this;
 }
コード例 #3
0
 /// <summary>
 /// This constructor initiates a node with a given value and a link that points to null.
 /// </summary>
 /// <param name="value"></param>
 public Node2(int value)
 {
     this.Value = value;
     this.Next  = null;
 }
コード例 #4
0
 /// <summary>
 /// A constructor to initialize a queue with the front property set to be null, back property set to be null, and count set to be zero.
 /// </summary>
 public Queue()
 {
     this.front = null;
     this.back  = null;
     this.count = 0;
 }