</pre>算法:顺序查找<p></p><p>*顺序查找与折半查找(二分查找)</p><p>*没有排序的数据:只能顺序查找</p><p>*顺序查找:速度慢</p><p>如果数据没有排序,只能使用顺序查找,如果已经排序可以进行折半查找(二分查找)。</p><p>如果没有排序,使用顺序查找100万个数据,平均需要找50万次!</p><p>如果已经排序,使用二分查找,平均二十万次就能完成。</p><p>顺序查找算法:</p><p><pre name="code" class="html">int SequentialSearch(int *a, const int n, const int x)
{
int i
for (i = 0; i < n; i++)
{
if (a[i] == x)
return i;
}
if(i=n) return -1;
}