< Summary

Information
Class: LeetCode.Algorithms.ImplementStackUsingQueues.ImplementStackUsingQueuesTwoQueues
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ImplementStackUsingQueues\ImplementStackUsingQueuesTwoQueues.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 76
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Push(...)100%66100%
Pop()100%22100%
Top()100%22100%
Empty()100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ImplementStackUsingQueues\ImplementStackUsingQueuesTwoQueues.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.ImplementStackUsingQueues;
 13
 14/// <inheritdoc />
 15public class ImplementStackUsingQueuesTwoQueues : IImplementStackUsingQueues
 16{
 717    private readonly Queue<int> _queue1 = new();
 718    private readonly Queue<int> _queue2 = new();
 19
 20    /// <summary>
 21    ///     Time complexity - O(n)
 22    ///     Space complexity - O(n)
 23    /// </summary>
 24    /// <param name="x"></param>
 25    public void Push(int x)
 1526    {
 1527        if (_queue1.Count > 0)
 528        {
 529            _queue2.Enqueue(x);
 30
 1231            while (_queue1.Count > 0)
 732            {
 733                _queue2.Enqueue(_queue1.Dequeue());
 734            }
 535        }
 36        else
 1037        {
 1038            _queue1.Enqueue(x);
 39
 1840            while (_queue2.Count > 0)
 841            {
 842                _queue1.Enqueue(_queue2.Dequeue());
 843            }
 1044        }
 1545    }
 46
 47    /// <summary>
 48    ///     Time complexity - O(1)
 49    ///     Space complexity - O(n)
 50    /// </summary>
 51    /// <returns></returns>
 52    public int Pop()
 953    {
 954        return _queue1.Count > 0 ? _queue1.Dequeue() : _queue2.Dequeue();
 955    }
 56
 57    /// <summary>
 58    ///     Time complexity - O(1)
 59    ///     Space complexity - O(n)
 60    /// </summary>
 61    /// <returns></returns>
 62    public int Top()
 563    {
 564        return _queue1.Count > 0 ? _queue1.Peek() : _queue2.Peek();
 565    }
 66
 67    /// <summary>
 68    ///     Time complexity - O(1)
 69    ///     Space complexity - O(n)
 70    /// </summary>
 71    /// <returns></returns>
 72    public bool Empty()
 473    {
 474        return _queue1.Count == 0 && _queue2.Count == 0;
 475    }
 76}