莱芜网站建设哪家好,汕头市网站建设公司,网站访问过程,职高网站建设知识点数据检索算法是指从数据集合#xff08;数组、表、哈希表等#xff09;中检索指定的数据项。
数据检索算法是所有算法的基础算法之一。
本文提供跳跃搜索的源代码。
1 文本格式
using System;
namespace Legalsoft.Truffer.Algorithm { public static class ArraySe… 数据检索算法是指从数据集合数组、表、哈希表等中检索指定的数据项。
数据检索算法是所有算法的基础算法之一。
本文提供跳跃搜索的源代码。
1 文本格式
using System;
namespace Legalsoft.Truffer.Algorithm { public static class ArraySearch_Algorithm { /// summary /// 跳跃搜索 /// /summary /// param namearr/param /// param namex/param /// returns/returns public static int Jump_Search(int[] arr, int x) { int n arr.Length; int step (int)Math.Sqrt(n); int prev 0; while (arr[Math.Min(step, n) - 1] x) { prev step; step (int)Math.Sqrt(n); if (prev n) { return -1; } } while (arr[prev] x) { prev; if (prev Math.Min(step, n)) { return -1; } } if (arr[prev] x) { return prev; } return -1; } } } 代码不重要思路最重要。 2 代码格式
using System;namespace Legalsoft.Truffer.Algorithm
{public static class ArraySearch_Algorithm{/// summary/// 跳跃搜索/// /summary/// param namearr/param/// param namex/param/// returns/returnspublic static int Jump_Search(int[] arr, int x){int n arr.Length;int step (int)Math.Sqrt(n);int prev 0;while (arr[Math.Min(step, n) - 1] x){prev step;step (int)Math.Sqrt(n);if (prev n){return -1;}}while (arr[prev] x){prev;if (prev Math.Min(step, n)){return -1;}}if (arr[prev] x){return prev;}return -1;}}
}