< 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
72%
Covered lines: 39
Uncovered lines: 15
Coverable lines: 54
Total lines: 138
Line coverage: 72.2%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.1%
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()50%10653.33%
Front()0%620%
Rear()50%2266.66%
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) 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.DesignCircularQueue;
 13
 14/// <inheritdoc />
 115public 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)
 528    {
 529        if (IsFull())
 130        {
 131            return false;
 32        }
 33
 434        if (_rear == null)
 135        {
 136            _rear = new Node(value);
 137            _front = _rear;
 138        }
 39        else
 340        {
 341            var node = new Node(value);
 42
 343            _rear.Next = node;
 44
 345            _rear = node;
 346        }
 47
 448        _count++;
 49
 450        return true;
 551    }
 52
 53    /// <summary>
 54    ///     Time complexity - O(1)
 55    ///     Space complexity - O(1)
 56    /// </summary>
 57    /// <returns></returns>
 58    public bool DeQueue()
 159    {
 160        if (IsEmpty())
 061        {
 062            return false;
 63        }
 64
 165        if (_front == null)
 066        {
 067            return false;
 68        }
 69
 170        _front = _front.Next;
 71
 172        _count--;
 73
 174        if (IsEmpty())
 075        {
 076            _rear = null;
 077        }
 78
 179        return true;
 180    }
 81
 82    /// <summary>
 83    ///     Time complexity - O(1)
 84    ///     Space complexity - O(1)
 85    /// </summary>
 86    /// <returns></returns>
 87    public int Front()
 088    {
 089        if (_front == null)
 090        {
 091            return -1;
 92        }
 93
 094        return _front.Value;
 095    }
 96
 97    /// <summary>
 98    ///     Time complexity - O(1)
 99    ///     Space complexity - O(1)
 100    /// </summary>
 101    /// <returns></returns>
 102    public int Rear()
 2103    {
 2104        if (_rear == null)
 0105        {
 0106            return -1;
 107        }
 108
 2109        return _rear.Value;
 2110    }
 111
 112    /// <summary>
 113    ///     Time complexity - O(1)
 114    ///     Space complexity - O(1)
 115    /// </summary>
 116    /// <returns></returns>
 117    public bool IsEmpty()
 2118    {
 2119        return _count == 0;
 2120    }
 121
 122    /// <summary>
 123    ///     Time complexity - O(1)
 124    ///     Space complexity - O(1)
 125    /// </summary>
 126    /// <returns></returns>
 127    public bool IsFull()
 6128    {
 6129        return _count == k;
 6130    }
 131
 4132    private class Node(int value)
 133    {
 4134        public Node? Next { get; set; }
 135
 6136        public int Value { get; } = value;
 137    }
 138}