mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-22 19:36:06 +00:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_searching;
|
||||
|
||||
public class linear_search {
|
||||
/* 线性查找(数组) */
|
||||
static int LinearSearchArray(int[] nums, int target) {
|
||||
int LinearSearchArray(int[] nums, int target) {
|
||||
// 遍历数组
|
||||
for (int i = 0; i < nums.Length; i++) {
|
||||
// 找到目标元素,返回其索引
|
||||
@@ -20,7 +20,7 @@ public class linear_search {
|
||||
}
|
||||
|
||||
/* 线性查找(链表) */
|
||||
static ListNode? LinearSearchLinkedList(ListNode? head, int target) {
|
||||
ListNode? LinearSearchLinkedList(ListNode? head, int target) {
|
||||
// 遍历链表
|
||||
while (head != null) {
|
||||
// 找到目标节点,返回之
|
||||
@@ -37,7 +37,7 @@ public class linear_search {
|
||||
int target = 3;
|
||||
|
||||
/* 在数组中执行线性查找 */
|
||||
int[] nums = { 1, 5, 3, 2, 4, 7, 5, 9, 10, 8 };
|
||||
int[] nums = [1, 5, 3, 2, 4, 7, 5, 9, 10, 8];
|
||||
int index = LinearSearchArray(nums, target);
|
||||
Console.WriteLine("目标元素 3 的索引 = " + index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user