mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 22:34:18 +08:00
Reformat the C# codes.
Disable creating new line before open brace.
This commit is contained in:
@ -9,36 +9,30 @@ using NUnit.Framework;
|
||||
namespace hello_algo.chapter_stack_and_queue;
|
||||
|
||||
/* 基于数组实现的栈 */
|
||||
class ArrayStack
|
||||
{
|
||||
class ArrayStack {
|
||||
private List<int> stack;
|
||||
public ArrayStack()
|
||||
{
|
||||
public ArrayStack() {
|
||||
// 初始化列表(动态数组)
|
||||
stack = new();
|
||||
}
|
||||
|
||||
/* 获取栈的长度 */
|
||||
public int size()
|
||||
{
|
||||
public int size() {
|
||||
return stack.Count();
|
||||
}
|
||||
|
||||
/* 判断栈是否为空 */
|
||||
public bool isEmpty()
|
||||
{
|
||||
public bool isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
/* 入栈 */
|
||||
public void push(int num)
|
||||
{
|
||||
public void push(int num) {
|
||||
stack.Add(num);
|
||||
}
|
||||
|
||||
/* 出栈 */
|
||||
public int pop()
|
||||
{
|
||||
public int pop() {
|
||||
if (isEmpty())
|
||||
throw new Exception();
|
||||
var val = peek();
|
||||
@ -47,25 +41,21 @@ class ArrayStack
|
||||
}
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
public int peek()
|
||||
{
|
||||
public int peek() {
|
||||
if (isEmpty())
|
||||
throw new Exception();
|
||||
return stack[size() - 1];
|
||||
}
|
||||
|
||||
/* 将 List 转化为 Array 并返回 */
|
||||
public int[] toArray()
|
||||
{
|
||||
public int[] toArray() {
|
||||
return stack.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class array_stack
|
||||
{
|
||||
public class array_stack {
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
public void Test() {
|
||||
/* 初始化栈 */
|
||||
ArrayStack stack = new ArrayStack();
|
||||
|
||||
|
Reference in New Issue
Block a user