static void Main(string[] args) { //1.使用BCL中的Stack<T> //Stack<char> stack = new Stack<char>(); //2.使用自己的顺序栈 //IStackDS<char> stack = new SeqStack<char>(30); //3.使用自己的链栈 IStackDS<char> stack = new LinkStack<char>(); stack.Push('a'); stack.Push('b'); stack.Push('c'); Console.WriteLine(stack.Count); char temp = stack.Pop(); //取得栈顶数据 并把栈顶的数据删除 Console.WriteLine(temp); Console.WriteLine(stack.Count); char temp2 = stack.Peek(); //取得栈顶的数据 不删除 Console.WriteLine(temp2); Console.WriteLine(stack.Count); stack.Clear(); Console.WriteLine(stack.Count); Console.ReadKey(); }
public void Move() { var x = 1; var y = 1; var linkStack = new LinkStack <Step>(); maze[1, 1] = 2; while (x <= exitX && y <= exitY) { if (x == exitX && y == exitY) { return; } if (maze[x - 1, y] == 0) { x -= 1; linkStack.Push(new Node <Step>(new Step { X = x, Y = y })); } else if (maze[x + 1, y] == 0) { x += 1; linkStack.Push(new Node <Step>(new Step { X = x, Y = y })); } else if (maze[x, y - 1] == 0) { y -= 1; linkStack.Push(new Node <Step>(new Step { X = x, Y = y })); } else if (maze[x, y + 1] == 0) { y += 1; linkStack.Push(new Node <Step>(new Step { X = x, Y = y })); } else { var stepNode = new Node <Step>(); linkStack.Pop(out stepNode); if (x == stepNode.Data.X && y == stepNode.Data.Y) { linkStack.Pop(out stepNode); } x = stepNode.Data.X; y = stepNode.Data.Y; } maze[x, y] = 2; } }
static void Main(string[] args) { IStack<string> stack = new LinkStack<string>(); stack.Push("a1"); stack.Push("a2"); stack.Push("a3"); while (stack.IsEmpty() == false) { Console.WriteLine(stack.StackTop); stack.Pop(); } }
/// <summary> ///GetLength 的测试 ///</summary> public void GetLengthTestHelper <T>() { LinkStack <T> target = new LinkStack <T>(); // TODO: 初始化为适当的值 int expected = 0; // TODO: 初始化为适当的值 int actual; actual = target.GetLength(); Assert.AreEqual(expected, actual); target.Push(default(T)); target.Push(default(T)); Assert.AreEqual <int>(2, target.GetLength()); }
public void PushAndPop() { var students = new Student[] { new Student { No = 1, Name = "李1", Score = 22.1 }, new Student { No = 2, Name = "李2", Score = 32.3 }, new Student { No = 3, Name = "李3", Score = 42.5 } }; var linkStack = new LinkStack <Student>(); foreach (var student in students) { linkStack.Push(new Node <Student>(student)); } var popStudent = new Node <Student>(); while (linkStack.Pop(out popStudent)) { } }
static void Main(string[] args) { //1.使用BCL中的Stack<T> IStackDS<Char> STACK = new LinkStack<char>(); STACK.Push('a'); STACK.Push('b'); STACK.Push('c'); Console.WriteLine(STACK.Count); char temp = STACK.pop();//取得栈顶数据,并把该数据删除 Console.WriteLine(temp); Console.WriteLine(STACK.Count); char temp2 = STACK.peek(); Console.WriteLine(temp2); Console.ReadKey(); }
public void PopStringTest() { LinkStack <string> target = new LinkStack <string>(); // TODO: 初始化为适当的值 target.Push("A"); target.Push("B"); target.Push("C"); Assert.AreEqual <string>("C", target.Pop()); Assert.AreEqual <string>("B", target.Pop()); Assert.AreEqual <string>("A", target.Pop()); Assert.AreEqual(0, target.Count); }
// //编写测试时,还可使用以下属性: // //使用 ClassInitialize 在运行类中的第一个测试前先运行代码 //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //使用 ClassCleanup 在运行完类中的所有测试后再运行代码 //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //使用 TestInitialize 在运行每个测试前先运行代码 //[TestInitialize()] //public void MyTestInitialize() //{ //} // //使用 TestCleanup 在运行完每个测试后运行代码 //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion /// <summary> ///Push 的测试 ///</summary> public void PushTestHelper <T>() { LinkStack <T> target = new LinkStack <T>(); // TODO: 初始化为适当的值 T p = default(T); // TODO: 初始化为适当的值 target.Push(p); Assert.AreEqual(1, target.Count); Assert.AreEqual(p, target.Pop()); }
/// <summary> ///GetPop 的测试 ///</summary> public void GetPopTestHelper <T>() { LinkStack <T> target = new LinkStack <T>(); // TODO: 初始化为适当的值 T expected = default(T); // TODO: 初始化为适当的值 T actual; target.Push(expected); actual = target.GetPop(); Assert.AreEqual(expected, actual); Assert.AreEqual <int>(1, target.Count); }
/// <summary> ///IsEmpty 的测试 ///</summary> public void IsEmptyTestHelper <T>() { LinkStack <T> target = new LinkStack <T>(); // TODO: 初始化为适当的值 bool expected = true; // TODO: 初始化为适当的值 bool actual; actual = target.IsEmpty(); Assert.AreEqual(expected, actual); target.Push(default(T)); Assert.IsFalse(target.IsEmpty()); }
public void TestAsserLinkStack() { LinkStack <int> A = new LinkStack <int>(); A.Push(1); A.Push(2); A.Push(3); A.Push(4); A.Push(5); //Pop //Normal int testnum1 = A.Pop(); //1 int testnum2 = A.Pop(); //2 Assert.AreEqual(5, testnum1); Assert.AreEqual(4, testnum2); //Edge A.Pop(); //3 A.Pop(); //4 A.Pop(); //5 }
void Start() { LinkStack <int> seqStack = new LinkStack <int>(); for (int i = 0; i < 3; i++) { seqStack.Push(i); } print("展示栈顶元素:" + seqStack.Peek()); print("栈数量:" + seqStack.GetLength()); for (int i = 0; i < 3; i++) { print(seqStack.Pop()); } }
public void ConversionOct(int n) //【例3-1】数制转换问题 { LinkStack <int> s = new LinkStack <int>(); while (n > 0) { s.Push(n % 8); n = n / 8; } while (!s.IsEmpty()) { n = s.Pop(); Console.WriteLine("{0}", n); } } //【例3-1】数制转换问题 //8进制转换//public void Conversion(int n)
/// <summary> /// 二进制转换 /// </summary> /// <param name="number">被转换的10进制数</param> static void ConvertTo(long number) { LinkStack <long> myLinkStack = new LinkStack <long>(); Console.WriteLine("input number:{0}:", number); while (number > 0) { myLinkStack.Push(number % 2); number = number / 2; } Console.Write("Result:"); while (!myLinkStack.IsEmpty()) { Console.Write(myLinkStack.Pop()); } }
public void Test() { LinkStack <int> stack = new LinkStack <int>(); stack.Push(1); stack.Push(2); stack.Push(3); Assert.Equal(3, stack.Pop()); Assert.Equal(2, stack.Pop()); Assert.Equal(1, stack.Pop()); stack.Push(1); stack.Push(2); Assert.Equal(2, stack.Pop()); Assert.Equal(1, stack.Pop()); stack.Push(3); Assert.Equal(3, stack.Pop()); }
public void PushLink(Int16 linkIndex) { LinkStack.Push(linkIndex); }
public void TestAsserLinkStack() { LinkStack<int> A = new LinkStack<int>(); A.Push(1); A.Push(2); A.Push(3); A.Push(4); A.Push(5); //Pop //Normal int testnum1 = A.Pop(); //1 int testnum2 = A.Pop(); //2 Assert.AreEqual(5, testnum1); Assert.AreEqual(4, testnum2); //Edge A.Pop(); //3 A.Pop(); //4 A.Pop(); //5 }