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 Vezba_03_2017
- {
- class QueueLNode
- {
- public QueueLNode(int content)
- {
- Content = content;
- }
- public int Content { get; set; }
- public QueueLNode next { get; set; }
- }
- class QueueL
- {
- private QueueLNode _head;
- private QueueLNode _tail;
- private int count = 0;
- public bool IsEmpty
- {
- get { return _head == null; }
- }
- public int Count { get { return count; } set { count = value; } }
- public void Put(int x)
- {
- QueueLNode newNode = new QueueLNode(x);
- if(IsEmpty)
- {
- _head = newNode;
- _tail = newNode;
- }
- else
- {
- _tail.next = newNode;
- _tail = newNode;
- }
- count++;
- }
- public int Get()
- {
- if (IsEmpty)
- throw new InvalidOperationException("The Queue is empty.");
- int x = _head.Content;
- if(_head == _tail)
- {
- _head = null;
- _tail = null;
- }
- else
- {
- _head = _head.next;
- }
- count--;
- return x;
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- QueueLNode node = _head;
- while (node != null)
- {
- sb.AppendFormat("{0} ", node.Content);
- node = node.next;
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement