< Summary

Information
Class: LeetCode.Algorithms.DesignCircularDeque.DesignCircularDequeLinkedList
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignCircularDeque\DesignCircularDequeLinkedList.cs
Line coverage
86%
Covered lines: 83
Uncovered lines: 13
Coverable lines: 96
Total lines: 211
Line coverage: 86.4%
Branch coverage
71%
Covered branches: 20
Total branches: 28
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
InsertFront(...)100%44100%
InsertLast(...)75%4487.5%
DeleteFront()37.5%11863.15%
DeleteLast()75%9878.94%
GetFront()100%22100%
GetRear()100%22100%
IsEmpty()100%11100%
IsFull()100%11100%
.ctor(...)100%11100%
get_Previous()100%11100%
get_Next()100%11100%
get_Value()100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DesignCircularDeque\DesignCircularDequeLinkedList.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.DesignCircularDeque;
 13
 14/// <inheritdoc />
 15public sealed class DesignCircularDequeLinkedList : IDesignCircularDeque
 16{
 17    private readonly int _k;
 18    private int _count;
 19    private DequeNode? _frontNode;
 20    private DequeNode? _rearNode;
 21
 422    public DesignCircularDequeLinkedList(int k)
 423    {
 424        _k = k;
 425    }
 26
 27    /// <summary>
 28    ///     Time complexity - O(1)
 29    ///     Space complexity - O(1)
 30    /// </summary>
 31    /// <param name="value"></param>
 32    /// <returns></returns>
 33    public bool InsertFront(int value)
 534    {
 535        if (IsFull())
 236        {
 237            return false;
 38        }
 39
 340        if (_frontNode == null)
 141        {
 142            _frontNode = new DequeNode(value);
 43
 144            _rearNode = _frontNode;
 145        }
 46        else
 247        {
 248            _frontNode.Previous = new DequeNode(value) { Next = _frontNode };
 49
 250            _frontNode = _frontNode.Previous;
 251        }
 52
 353        _count++;
 54
 355        return true;
 556    }
 57
 58    /// <summary>
 59    ///     Time complexity - O(1)
 60    ///     Space complexity - O(1)
 61    /// </summary>
 62    /// <param name="value"></param>
 63    /// <returns></returns>
 64    public bool InsertLast(int value)
 465    {
 466        if (IsFull())
 067        {
 068            return false;
 69        }
 70
 471        if (_rearNode == null)
 272        {
 273            _rearNode = new DequeNode(value);
 74
 275            _frontNode = _rearNode;
 276        }
 77        else
 278        {
 279            _rearNode.Next = new DequeNode(value) { Previous = _rearNode };
 80
 281            _rearNode = _rearNode.Next;
 282        }
 83
 484        _count++;
 85
 486        return true;
 487    }
 88
 89    /// <summary>
 90    ///     Time complexity - O(1)
 91    ///     Space complexity - O(1)
 92    /// </summary>
 93    /// <returns></returns>
 94    public bool DeleteFront()
 295    {
 296        if (IsEmpty())
 197        {
 198            return false;
 99        }
 100
 1101        if (_count == 1)
 1102        {
 1103            _frontNode = null;
 1104            _rearNode = null;
 1105        }
 106        else
 0107        {
 0108            _frontNode = _frontNode?.Next;
 109
 0110            if (_frontNode != null)
 0111            {
 0112                _frontNode.Previous = null;
 0113            }
 0114        }
 115
 1116        _count--;
 117
 1118        return true;
 2119    }
 120
 121    /// <summary>
 122    ///     Time complexity - O(1)
 123    ///     Space complexity - O(1)
 124    /// </summary>
 125    /// <returns></returns>
 126    public bool DeleteLast()
 3127    {
 3128        if (IsEmpty())
 1129        {
 1130            return false;
 131        }
 132
 2133        if (_count == 1)
 0134        {
 0135            _frontNode = null;
 0136            _rearNode = null;
 0137        }
 138        else
 2139        {
 2140            _rearNode = _rearNode?.Previous;
 141
 2142            if (_rearNode != null)
 2143            {
 2144                _rearNode.Next = null;
 2145            }
 2146        }
 147
 2148        _count--;
 149
 2150        return true;
 3151    }
 152
 153    /// <summary>
 154    ///     Time complexity - O(1)
 155    ///     Space complexity - O(1)
 156    /// </summary>
 157    /// <returns></returns>
 158    public int GetFront()
 4159    {
 4160        if (_frontNode == null)
 1161        {
 1162            return -1;
 163        }
 164
 3165        return _frontNode.Value;
 4166    }
 167
 168    /// <summary>
 169    ///     Time complexity - O(1)
 170    ///     Space complexity - O(1)
 171    /// </summary>
 172    /// <returns></returns>
 173    public int GetRear()
 4174    {
 4175        if (_rearNode == null)
 1176        {
 1177            return -1;
 178        }
 179
 3180        return _rearNode.Value;
 4181    }
 182
 183    /// <summary>
 184    ///     Time complexity - O(1)
 185    ///     Space complexity - O(1)
 186    /// </summary>
 187    /// <returns></returns>
 188    public bool IsEmpty()
 7189    {
 7190        return _count == 0;
 7191    }
 192
 193    /// <summary>
 194    ///     Time complexity - O(1)
 195    ///     Space complexity - O(1)
 196    /// </summary>
 197    /// <returns></returns>
 198    public bool IsFull()
 11199    {
 11200        return _count == _k;
 11201    }
 202
 7203    private class DequeNode(int value)
 204    {
 8205        public DequeNode? Previous { get; set; }
 206
 8207        public DequeNode? Next { get; set; }
 208
 13209        public int Value { get; } = value;
 210    }
 211}