< Summary

Information
Class: LeetCode.Algorithms.DesignCircularQueue.DesignCircularQueueLinkedList
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignCircularQueue\DesignCircularQueueLinkedList.cs
Line coverage
96%
Covered lines: 52
Uncovered lines: 2
Coverable lines: 54
Total lines: 138
Line coverage: 96.2%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
EnQueue(...)100%44100%
DeQueue()83.33%6686.66%
Front()100%22100%
Rear()100%22100%
IsEmpty()100%11100%
IsFull()100%11100%
.ctor(...)100%11100%
get_Next()100%11100%
get_Value()100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignCircularQueue\DesignCircularQueueLinkedList.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.DesignCircularQueue;
 13
 14/// <inheritdoc />
 415public sealed class DesignCircularQueueLinkedList(int k) : IDesignCircularQueue
 16{
 17    private int _count;
 18    private Node? _front;
 19    private Node? _rear;
 20
 21    /// <summary>
 22    ///     Time complexity - O(1)
 23    ///     Space complexity - O(1)
 24    /// </summary>
 25    /// <param name="value"></param>
 26    /// <returns></returns>
 27    public bool EnQueue(int value)
 928    {
 929        if (IsFull())
 230        {
 231            return false;
 32        }
 33
 734        if (_rear == null)
 335        {
 336            _rear = new Node(value);
 337            _front = _rear;
 338        }
 39        else
 440        {
 441            var node = new Node(value);
 42
 443            _rear.Next = node;
 44
 445            _rear = node;
 446        }
 47
 748        _count++;
 49
 750        return true;
 951    }
 52
 53    /// <summary>
 54    ///     Time complexity - O(1)
 55    ///     Space complexity - O(1)
 56    /// </summary>
 57    /// <returns></returns>
 58    public bool DeQueue()
 459    {
 460        if (IsEmpty())
 161        {
 162            return false;
 63        }
 64
 365        if (_front == null)
 066        {
 067            return false;
 68        }
 69
 370        _front = _front.Next;
 71
 372        _count--;
 73
 374        if (IsEmpty())
 175        {
 176            _rear = null;
 177        }
 78
 379        return true;
 480    }
 81
 82    /// <summary>
 83    ///     Time complexity - O(1)
 84    ///     Space complexity - O(1)
 85    /// </summary>
 86    /// <returns></returns>
 87    public int Front()
 388    {
 389        if (_front == null)
 190        {
 191            return -1;
 92        }
 93
 294        return _front.Value;
 395    }
 96
 97    /// <summary>
 98    ///     Time complexity - O(1)
 99    ///     Space complexity - O(1)
 100    /// </summary>
 101    /// <returns></returns>
 102    public int Rear()
 5103    {
 5104        if (_rear == null)
 1105        {
 1106            return -1;
 107        }
 108
 4109        return _rear.Value;
 5110    }
 111
 112    /// <summary>
 113    ///     Time complexity - O(1)
 114    ///     Space complexity - O(1)
 115    /// </summary>
 116    /// <returns></returns>
 117    public bool IsEmpty()
 9118    {
 9119        return _count == 0;
 9120    }
 121
 122    /// <summary>
 123    ///     Time complexity - O(1)
 124    ///     Space complexity - O(1)
 125    /// </summary>
 126    /// <returns></returns>
 127    public bool IsFull()
 11128    {
 11129        return _count == k;
 11130    }
 131
 7132    private class Node(int value)
 133    {
 7134        public Node? Next { get; set; }
 135
 13136        public int Value { get; } = value;
 137    }
 138}