1.顺序查找
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 数据结构和算法 { class _2 { public readonly static int[] arrayList = new int[] { 312, 564, 1254, 145, 212, 884, 145, 1212, 443, 56, 222 }; static void Main() { int[] numbers = new int[100]; for (int i = 0; i < arrayList.Length; i++) { numbers[i] = arrayList[i]; } int searchNumber; Console.WriteLine("输入一个数字:"); searchNumber = int.Parse(Console.ReadLine()); bool found; found = seqSerch(numbers, searchNumber); if (found) { Console.WriteLine(searchNumber +"找到了!"); } else { Console.WriteLine(searchNumber + "没有在数组中!"); } Console.ReadKey(); } static bool seqSerch(int[] arr, int sValue) { for (int i = 0; i < arr.Length; i++) { if (arr[i] == sValue) { return true; } } return false; } } }
2.二叉查找
3.递归二叉查找
时间: 2024-10-26 21:21:56