public void Push(T item) { while (_firstStack.Count > 0 && IsLessThan(_firstStack.Peek(), item)) { _secondStack.Push(_firstStack.Pop()); } _firstStack.Push(item); while (_secondStack.Count > 0) { _firstStack.Push(_secondStack.Pop()); } }
private void RearangeStacks() { while (_firstStack.Count != 0) { _secondStack.Push(_firstStack.Pop()); } }
public void Should_Push_And_Pop_Correct_Order() { //arrange var data = new int[] { 1, 2, 3 }; var stack = new MyLinkedListStack <int>(); //act stack.Push(data[0]); stack.Push(data[1]); stack.Push(data[2]); var first = stack.Pop(); var second = stack.Pop(); var third = stack.Pop(); //assert first.ShouldBeEquivalentTo(data[2]); second.ShouldBeEquivalentTo(data[1]); third.ShouldBeEquivalentTo(data[0]); }
public void Should_Push() { //arrange var stack = new MyLinkedListStack <int>(); //act stack.Push(1); //assert stack.Count.ShouldBeEquivalentTo(1); }
public void Should_Check_Is_Empty_False() { //arrange var stack = new MyLinkedListStack <int>(); stack.Push(1); //act var result = stack.IsEmpty(); //assert result.ShouldBeEquivalentTo(false); }
public void Enqueue(T item) { _firstStack.Push(item); }