public void StackWithLinkedList_IsFull_should_return_false_when_stack_has_less_elements() { StackWithLinkedList <int> st2 = new StackWithLinkedList <int>(2); st2.Push(1); Assert.AreEqual(false, st2.IsFull()); }
public void StackWithLinkedList_IsFull_should_return_true_when_stack_has_capacity_number_of_elements() { StackWithLinkedList <int> st2 = new StackWithLinkedList <int>(2); st2.Push(1); st2.Push(3); Assert.AreEqual(true, st2.IsFull()); }
public void Push_An_Element() { var stack = new StackWithLinkedList <int>(); stack.Push(10); Assert.Equal(1, stack.Length); Assert.Equal(10, stack.Top.Value); Assert.Equal(10, stack.Bottom.Value); }
public void Stack_Is_Empty() { var stack = new StackWithLinkedList <int>(); var isEmpty = stack.IsEmpty(); Assert.True(isEmpty); Assert.Equal(0, stack.Length); Assert.Null(stack.Top); Assert.Null(stack.Bottom); }
public void Peek_An_Element_In_A_Stack_With_No_Element() { var stack = new StackWithLinkedList <int>(); var item = stack.Peek(); Assert.Equal(0, item); Assert.Equal(0, stack.Length); Assert.Null(stack.Top); Assert.Null(stack.Bottom); }
public void Stack_Is_Not_Empty() { var stack = new StackWithLinkedList <int>(); stack.Push(10); var isEmpty = stack.IsEmpty(); Assert.False(isEmpty); Assert.Equal(1, stack.Length); Assert.NotNull(stack.Top); Assert.NotNull(stack.Bottom); }
public void Pop_An_Element_In_A_Stack_With_One_Element() { var stack = new StackWithLinkedList <int>(); stack.Push(20); var item = stack.Pop(); Assert.Equal(20, item); Assert.Equal(0, stack.Length); Assert.Null(stack.Top); Assert.Null(stack.Bottom); }
public void Peek_Element_In_A_Stack_With_One_Element() { var stack = new StackWithLinkedList <int>(); stack.Push(20); var item = stack.Peek(); Assert.Equal(20, item); Assert.Equal(1, stack.Length); Assert.Equal(20, stack.Top.Value); Assert.Equal(20, stack.Bottom.Value); }
public void Pop_An_Element_In_A_Stack_With_Two_Elements() { var stack = new StackWithLinkedList <int>(); stack.Push(10); stack.Push(20); var item = stack.Pop(); Assert.Equal(20, item); Assert.Equal(1, stack.Length); Assert.Equal(10, stack.Top.Value); Assert.Equal(10, stack.Bottom.Value); }
public void StackWithLinkedList_Constructor_should_throw_exception_when_capacity_is_zero() { try { StackWithLinkedList <int> st2 = new StackWithLinkedList <int>(0); Assert.Fail(); } catch (ArgumentOutOfRangeException) { Assert.IsTrue(true); } catch (Exception) { Assert.Fail(); } }
private void Stack_Implementation_Of_Linkedlist_Click(object sender, EventArgs e) { StackWithLinkedList list = new StackWithLinkedList(); Console.WriteLine("Checking Is Empty - " + list.IsEmpty()); Console.WriteLine("Push 5 - "); list.Push(5); Console.WriteLine("Push 4 - "); list.Push(4); Console.WriteLine("Push 3 - "); list.Push(3); Console.WriteLine("Pop 3 - " + list.Pop().data); Console.WriteLine("Pop 4 - " + list.Pop().data); Console.WriteLine("Checking Is Empty - " + list.IsEmpty()); Console.WriteLine("Pop 5 - " + list.Pop().data); Console.WriteLine("Checking Is Empty - " + list.IsEmpty()); }
public long largestRectangle(int[] h) { // first of all i define variable which type is stack. var _stack = new StackWithLinkedList <int>(); var _maximum_area = 0; //as a result that should return at the end of method var _lengthOfArray = h.Length; var _counter = 0; // secondly start from first bar, and do following for every bar ‘h[i]’ where ‘_counter’ varies from 0 to _lengthOfArray-1. while (_counter < _lengthOfArray) { if (_stack.IsNull() || h[_stack.Peek()] <= h[_counter]) { _stack.Push(_counter++); } else if (h[_stack.Peek()] > h[_counter]) { //keep top of stack and remove it var _topOfStack = _stack.Pop(); //calculate with top of stack var _calculateArea = h[_topOfStack] * (_stack.IsNull() ? _counter : _counter - _stack.Peek() - 1); if (_maximum_area < _calculateArea) { _maximum_area = _calculateArea; } } } //finally if stack not is null should remove one by one from stack and calculate area with each one while (!_stack.IsNull()) { //keep top of stack and remove it var _topOfStack = _stack.Pop(); //calculate with top of stack var _calculateArea = h[_topOfStack] * (_stack.IsNull() ? _counter : _counter - _stack.Peek() - 1); if (_maximum_area < _calculateArea) { _maximum_area = _calculateArea; } } return(_maximum_area); }
public void StackWithLinkedList_Push_should_throw_exception_when_stack_is_full() { StackWithLinkedList <int> st2 = new StackWithLinkedList <int>(2); st2.Push(1); st2.Push(3); try { st2.Push(4); Assert.Fail(); } catch (InvalidOperationException ex) { Assert.AreEqual("The stack is full", ex.Message); } catch (Exception) { Assert.Fail(); } }
public override void Push(int value) { base.Push(value); var sorted = new StackWithLinkedList <int>(); while (!base.IsEmpty()) { int element = base.Pop(); while (!sorted.IsEmpty() && sorted.Peek() > element) { base.Push(sorted.Pop()); } sorted.Push(element); } while (!sorted.IsEmpty()) { base.Push(sorted.Pop()); } }
public void SetUp() { _stack = new StackWithLinkedList <int>(); }