Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Book3
- {
- class Queue<T>
- {
- private Node<T> head, last;
- public Queue()
- {
- this.head = null;
- this.last = null;
- }
- public bool IsEmpty()
- {
- return this.head == null;
- }
- public T Head()
- {
- return this.head.GetValue();
- }
- public void Insert(T x)
- {
- Node<T> connectionEnd = new Node<T>(x);
- if (this.head == null)
- this.head = connectionEnd;
- if (this.last != null)
- this.last.SetNext(connectionEnd);
- this.last = connectionEnd;
- }
- public T Remove()
- {
- T value = this.Head();
- this.head = this.head.GetNext();
- if (this.head == null)
- this.last = null;
- return value;
- }
- public override string ToString()
- {
- string s = "[";
- Node<T> curr = this.head;
- while (curr != null)
- {
- s += curr.GetValue().ToString();
- s += ", ";
- }
- s += "]";
- return s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement