mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
refactor: add/refactor method in include, simplified print code (#471)
This commit is contained in:
@ -23,7 +23,7 @@ public class stack
|
||||
stack.Push(5);
|
||||
stack.Push(4);
|
||||
// 请注意,stack.ToArray() 得到的是倒序序列,即索引 0 为栈顶
|
||||
Console.WriteLine("栈 stack = " + string.Join(",", stack.ToArray()));
|
||||
Console.WriteLine("栈 stack = " + string.Join(",", stack));
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
int peek = stack.Peek();
|
||||
@ -31,7 +31,7 @@ public class stack
|
||||
|
||||
/* 元素出栈 */
|
||||
int pop = stack.Pop();
|
||||
Console.WriteLine("出栈元素 pop = " + pop + ",出栈后 stack = " + string.Join(",", stack.ToArray()));
|
||||
Console.WriteLine("出栈元素 pop = " + pop + ",出栈后 stack = " + string.Join(",", stack));
|
||||
|
||||
/* 获取栈的长度 */
|
||||
int size = stack.Count();
|
||||
|
||||
Reference in New Issue
Block a user