Skip to content

Commit

Permalink
1. Remove unused libs.
Browse files Browse the repository at this point in the history
2. Add file headers.
3. Modify file name to match Java's.
4. Fix some issues.
  • Loading branch information
krahets committed Dec 23, 2022
1 parent a427cb1 commit c429e5f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 49 deletions.
4 changes: 2 additions & 2 deletions codes/csharp/chapter_array_and_linkedlist/Array.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// File: Array.cs
// File: array.cs
// Created Time: 2022-12-14
// Author: mingXta ([email protected])

using NUnit.Framework;

namespace hello_algo.chapter_array_and_linkedlist
{
public class Array
public class array
{
/// <summary>
/// 随机返回一个数组元素
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// File: LinkedList.cs
// File: linked_list.cs
// Created Time: 2022-12-16
// Author: mingXta ([email protected])

Expand All @@ -7,14 +7,14 @@

namespace hello_algo.chapter_array_and_linkedlist
{
public class LinkedList
public class linked_list
{
/// <summary>
/// 在链表的结点 n0 之后插入结点 P
/// </summary>
public static void Insert(ListNode n0, ListNode P)
{
ListNode n1 = n0.next;
ListNode? n1 = n0.next;
n0.next = P;
P.next = n1;
}
Expand All @@ -28,7 +28,7 @@ public static void Remove(ListNode n0)
return;
// n0 -> P -> n1
ListNode P = n0.next;
ListNode n1 = P.next;
ListNode? n1 = P.next;
n0.next = n1;
}

Expand Down Expand Up @@ -78,15 +78,15 @@ public void Test()
n1.next = n2;
n2.next = n3;
n3.next = n4;
Console.WriteLine($"初始化的链表为{n0}");
Console.WriteLine($"初始化的链表为 {n0}");

// 插入结点
Insert(n0, new ListNode(0));
Console.WriteLine($"插入结点后的链表为{n0}");
Console.WriteLine($"插入结点后的链表为 {n0}");

// 删除结点
Remove(n0);
Console.WriteLine($"删除结点后的链表为{n0}");
Console.WriteLine($"删除结点后的链表为 {n0}");

// 访问结点
ListNode? node = Access(n0, 3);
Expand Down
13 changes: 5 additions & 8 deletions codes/csharp/chapter_array_and_linkedlist/list.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Newtonsoft.Json.Linq;
// File: list.cs
// Created Time: 2022-12-16
// Author: mingXta ([email protected])

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace hello_algo.chapter_array_and_linkedlist
{
Expand Down Expand Up @@ -46,7 +43,7 @@ public void Test()
Console.WriteLine("在索引 3 处插入数字 6 ,得到 list = " + string.Join(",", list));

/* 删除元素 */
list.Remove(3);
list.RemoveAt(3);
Console.WriteLine("删除索引 3 处的元素,得到 list = " + string.Join(",", list));

/* 通过索引遍历列表 */
Expand Down
10 changes: 4 additions & 6 deletions codes/csharp/chapter_array_and_linkedlist/my_list.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Newtonsoft.Json.Linq;
// File: my_list.cs
// Created Time: 2022-12-16
// Author: mingXta ([email protected])

using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace hello_algo.chapter_array_and_linkedlist
{
Expand Down
6 changes: 3 additions & 3 deletions codes/csharp/include/ListNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace hello_algo.include
public class ListNode
{
public int val;
public ListNode next;
public ListNode? next;

/// <summary>
/// Generate a linked list with an array
Expand All @@ -26,7 +26,7 @@ public ListNode(int x)
/// </summary>
/// <param name="arr"></param>
/// <returns></returns>
public static ListNode ArrToLinkedList(int[] arr)
public static ListNode? ArrToLinkedList(int[] arr)
{
ListNode dum = new ListNode(0);
ListNode head = dum;
Expand All @@ -44,7 +44,7 @@ public static ListNode ArrToLinkedList(int[] arr)
/// <param name="head"></param>
/// <param name="val"></param>
/// <returns></returns>
public static ListNode GetListNode(ListNode head, int val)
public static ListNode? GetListNode(ListNode? head, int val)
{
while (head != null && head.val != val)
{
Expand Down
26 changes: 4 additions & 22 deletions codes/csharp/include/PrintUtil.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// File: ListNode.cs
// Created Time: 2022-12-16
// Author: mingXta ([email protected])

namespace hello_algo.include
{
Expand All @@ -21,21 +18,6 @@ public Trunk(Trunk? prev, String str)

public class PrintUtil
{
/**
* Print a linked list
* @param head
*/
public static void printLinkedList(ListNode head)
{
List<String> list = new();
while (head != null)
{
list.Add(head.val.ToString());
head = head.next;
}
Console.Write(String.Join(" -> ", list));
}

/**
* The interface of the tree printer
* This tree printer is borrowed from TECHIE DELIGHT
Expand Down Expand Up @@ -81,7 +63,7 @@ public static void printTree(TreeNode? root, Trunk? prev, bool isLeft)
}

showTrunks(trunk);
Console.Write(" " + root.val);
Console.WriteLine(" " + root.val);

if (prev != null)
{
Expand Down
6 changes: 5 additions & 1 deletion codes/csharp/include/TreeNode.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// File: ListNode.cs
// Created Time: 2022-12-16
// Author: mingXta ([email protected])

namespace hello_algo.include
{
public class TreeNode
{
public int? val; // 结点值
public int height; // 结点高度
public int height; // 结点高度
public TreeNode? left; // 左子结点引用
public TreeNode? right; // 右子结点引用

Expand Down

0 comments on commit c429e5f

Please sign in to comment.