mirror of
https://github.com/krahets/hello-algo.git
synced 2025-01-23 14:20:29 +08:00
Unify the comment format of C# codes.
This commit is contained in:
parent
b5019b0494
commit
b7e09c4c1d
@ -8,9 +8,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
{
|
||||
public class Array
|
||||
{
|
||||
/// <summary>
|
||||
/// 随机返回一个数组元素
|
||||
/// </summary>
|
||||
/* 随机返回一个数组元素 */
|
||||
public static int RandomAccess(int[] nums)
|
||||
{
|
||||
Random random = new();
|
||||
@ -19,9 +17,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
return randomNum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 扩展数组长度
|
||||
/// </summary>
|
||||
/* 扩展数组长度 */
|
||||
public static int[] Extend(int[] nums, int enlarge)
|
||||
{
|
||||
// 初始化一个扩展长度后的数组
|
||||
@ -35,9 +31,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在数组的索引 index 处插入元素 num
|
||||
/// </summary>
|
||||
/* 在数组的索引 index 处插入元素 num */
|
||||
public static void Insert(int[] nums, int num, int index)
|
||||
{
|
||||
// 把索引 index 以及之后的所有元素向后移动一位
|
||||
@ -49,9 +43,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
nums[index] = num;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除索引 index 处元素
|
||||
/// </summary>
|
||||
/* 删除索引 index 处元素 */
|
||||
public static void Remove(int[] nums, int index)
|
||||
{
|
||||
// 把索引 index 之后的所有元素向前移动一位
|
||||
@ -61,9 +53,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 遍历数组
|
||||
/// </summary>
|
||||
/* 遍历数组 */
|
||||
public static void Traverse(int[] nums)
|
||||
{
|
||||
int count = 0;
|
||||
@ -79,9 +69,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在数组中查找指定元素
|
||||
/// </summary>
|
||||
/* 在数组中查找指定元素 */
|
||||
public static int Find(int[] nums, int target)
|
||||
{
|
||||
for (int i = 0; i < nums.Length; i++)
|
||||
@ -92,15 +80,13 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 辅助函数,数组转字符串
|
||||
/// </summary>
|
||||
/* 辅助函数,数组转字符串 */
|
||||
public static string ToString(int[] nums)
|
||||
{
|
||||
return string.Join(",", nums);
|
||||
}
|
||||
|
||||
// Driver Code
|
||||
|
||||
[Test]
|
||||
public static void Test()
|
||||
{
|
||||
|
@ -9,9 +9,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
{
|
||||
public class linked_list
|
||||
{
|
||||
/// <summary>
|
||||
/// 在链表的结点 n0 之后插入结点 P
|
||||
/// </summary>
|
||||
/* 在链表的结点 n0 之后插入结点 P */
|
||||
public static void Insert(ListNode n0, ListNode P)
|
||||
{
|
||||
ListNode? n1 = n0.next;
|
||||
@ -19,9 +17,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
P.next = n1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除链表的结点 n0 之后的首个结点
|
||||
/// </summary>
|
||||
/* 删除链表的结点 n0 之后的首个结点 */
|
||||
public static void Remove(ListNode n0)
|
||||
{
|
||||
if (n0.next == null)
|
||||
@ -32,9 +28,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
n0.next = n1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 访问链表中索引为 index 的结点
|
||||
/// </summary>
|
||||
/* 访问链表中索引为 index 的结点 */
|
||||
public static ListNode? Access(ListNode head, int index)
|
||||
{
|
||||
for (int i = 0; i < index; i++)
|
||||
@ -46,9 +40,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
return head;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在链表中查找值为 target 的首个结点
|
||||
/// </summary>
|
||||
/* 在链表中查找值为 target 的首个结点 */
|
||||
public static int Find(ListNode head, int target)
|
||||
{
|
||||
int index = 0;
|
||||
@ -62,7 +54,7 @@ namespace hello_algo.chapter_array_and_linkedlist
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Driver Code
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
|
@ -35,11 +35,7 @@ namespace hello_algo.chapter_tree
|
||||
return root;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找结点
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <returns></returns>
|
||||
/* 查找结点 */
|
||||
public TreeNode? search(int num)
|
||||
{
|
||||
TreeNode? cur = root;
|
||||
|
@ -12,11 +12,7 @@ namespace hello_algo.chapter_tree
|
||||
public class binary_tree_bfs
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 层序遍历
|
||||
/// </summary>
|
||||
/// <param name="root"></param>
|
||||
/// <returns></returns>
|
||||
/* 层序遍历 */
|
||||
public List<int> hierOrder(TreeNode root)
|
||||
{
|
||||
// 初始化队列,加入根结点
|
||||
|
@ -13,10 +13,7 @@ namespace hello_algo.chapter_tree
|
||||
{
|
||||
List<int> list = new();
|
||||
|
||||
/// <summary>
|
||||
/// 前序遍历
|
||||
/// </summary>
|
||||
/// <param name="root"></param>
|
||||
/* 前序遍历 */
|
||||
void preOrder(TreeNode? root)
|
||||
{
|
||||
if (root == null) return;
|
||||
@ -26,10 +23,7 @@ namespace hello_algo.chapter_tree
|
||||
preOrder(root.right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中序遍历
|
||||
/// </summary>
|
||||
/// <param name="root"></param>
|
||||
/* 中序遍历 */
|
||||
void inOrder(TreeNode? root)
|
||||
{
|
||||
if (root == null) return;
|
||||
@ -39,10 +33,7 @@ namespace hello_algo.chapter_tree
|
||||
inOrder(root.right);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 后序遍历
|
||||
/// </summary>
|
||||
/// <param name="root"></param>
|
||||
/* 后序遍历 */
|
||||
void postOrder(TreeNode? root)
|
||||
{
|
||||
if (root == null) return;
|
||||
|
Loading…
Reference in New Issue
Block a user