< 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
63%
Covered lines: 61
Uncovered lines: 35
Coverable lines: 96
Total lines: 211
Line coverage: 63.5%
Branch coverage
46%
Covered branches: 13
Total branches: 28
Branch coverage: 46.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(...)75%4475%
InsertLast(...)75%4487.5%
DeleteFront()0%7280%
DeleteLast()62.5%10868.42%
GetFront()50%2266.66%
GetRear()50%2266.66%
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) 2025 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 class DesignCircularDequeLinkedList : IDesignCircularDeque
 16{
 17    private readonly int _k;
 18    private int _count;
 19    private DequeNode? _frontNode;
 20    private DequeNode? _rearNode;
 21
 122    public DesignCircularDequeLinkedList(int k)
 123    {
 124        _k = k;
 125    }
 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)
 334    {
 335        if (IsFull())
 136        {
 137            return false;
 38        }
 39
 240        if (_frontNode == null)
 041        {
 042            _frontNode = new DequeNode(value);
 43
 044            _rearNode = _frontNode;
 045        }
 46        else
 247        {
 248            _frontNode.Previous = new DequeNode(value) { Next = _frontNode };
 49
 250            _frontNode = _frontNode.Previous;
 251        }
 52
 253        _count++;
 54
 255        return true;
 356    }
 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)
 265    {
 266        if (IsFull())
 067        {
 068            return false;
 69        }
 70
 271        if (_rearNode == null)
 172        {
 173            _rearNode = new DequeNode(value);
 74
 175            _frontNode = _rearNode;
 176        }
 77        else
 178        {
 179            _rearNode.Next = new DequeNode(value) { Previous = _rearNode };
 80
 181            _rearNode = _rearNode.Next;
 182        }
 83
 284        _count++;
 85
 286        return true;
 287    }
 88
 89    /// <summary>
 90    ///     Time complexity - O(1)
 91    ///     Space complexity - O(1)
 92    /// </summary>
 93    /// <returns></returns>
 94    public bool DeleteFront()
 095    {
 096        if (IsEmpty())
 097        {
 098            return false;
 99        }
 100
 0101        if (_count == 1)
 0102        {
 0103            _frontNode = null;
 0104            _rearNode = null;
 0105        }
 106        else
 0107        {
 0108            _frontNode = _frontNode?.Next;
 109
 0110            if (_frontNode != null)
 0111            {
 0112                _frontNode.Previous = null;
 0113            }
 0114        }
 115
 0116        _count--;
 117
 0118        return true;
 0119    }
 120
 121    /// <summary>
 122    ///     Time complexity - O(1)
 123    ///     Space complexity - O(1)
 124    /// </summary>
 125    /// <returns></returns>
 126    public bool DeleteLast()
 1127    {
 1128        if (IsEmpty())
 0129        {
 0130            return false;
 131        }
 132
 1133        if (_count == 1)
 0134        {
 0135            _frontNode = null;
 0136            _rearNode = null;
 0137        }
 138        else
 1139        {
 1140            _rearNode = _rearNode?.Previous;
 141
 1142            if (_rearNode != null)
 1143            {
 1144                _rearNode.Next = null;
 1145            }
 1146        }
 147
 1148        _count--;
 149
 1150        return true;
 1151    }
 152
 153    /// <summary>
 154    ///     Time complexity - O(1)
 155    ///     Space complexity - O(1)
 156    /// </summary>
 157    /// <returns></returns>
 158    public int GetFront()
 1159    {
 1160        if (_frontNode == null)
 0161        {
 0162            return -1;
 163        }
 164
 1165        return _frontNode.Value;
 1166    }
 167
 168    /// <summary>
 169    ///     Time complexity - O(1)
 170    ///     Space complexity - O(1)
 171    /// </summary>
 172    /// <returns></returns>
 173    public int GetRear()
 1174    {
 1175        if (_rearNode == null)
 0176        {
 0177            return -1;
 178        }
 179
 1180        return _rearNode.Value;
 1181    }
 182
 183    /// <summary>
 184    ///     Time complexity - O(1)
 185    ///     Space complexity - O(1)
 186    /// </summary>
 187    /// <returns></returns>
 188    public bool IsEmpty()
 1189    {
 1190        return _count == 0;
 1191    }
 192
 193    /// <summary>
 194    ///     Time complexity - O(1)
 195    ///     Space complexity - O(1)
 196    /// </summary>
 197    /// <returns></returns>
 198    public bool IsFull()
 6199    {
 6200        return _count == _k;
 6201    }
 202
 4203    private class DequeNode(int value)
 204    {
 6205        public DequeNode? Previous { get; set; }
 206
 5207        public DequeNode? Next { get; set; }
 208
 6209        public int Value { get; } = value;
 210    }
 211}