算法-->顺序查找
来源:互联网 发布:nestopia mac 编辑:程序博客网 时间:2024/06/03 16:48
package 顺序查找;import java.util.Scanner;public class ShunXu { static final int N = 15; static int searchFun(int a[], int n, int x) { int i, f = -1; for (i = 0; i < n; i++) { if (x == a[i]) { f = i; break; } } return f; } public static void main(String[] args) { int x, n, i; ShunXu sh = new ShunXu(); int[] shuzu = new int[N]; for (i = 0; i < N; i++) { shuzu[i] = (int) (100 + Math.random() * (100 + 1)); } System.out.print("顺序查找演示\n"); System.out.print("数据序列\n"); for (i = 0; i < N; i++) { System.out.print(" " + shuzu[i]); } System.out.print("\n\n"); System.out.print("输入要查找的数\n"); Scanner sc = new Scanner(System.in); x = sc.nextInt(); n = searchFun(shuzu, N, x); if (n < 0) { System.out.print("没找到数据" + x); } else { System.out.println("数据 " + x + "位于数据的第" + (n + 1) + "个元素处"); } }}
阅读全文
0 0
- [转载]查找算法----顺序查找
- 查找算法之顺序查找
- 查找算法_顺序查找
- 【算法-查找之一】顺序查找
- 查找算法之顺序查找
- 查找算法之顺序查找
- //顺序查找算法
- 顺序表查找算法
- java顺序查找算法
- 算法 :顺序查找
- 顺序表查找算法
- 算法:顺序查找
- 算法---顺序查找
- 算法-->顺序查找
- 检索算法 ---顺序查找
- 顺序查找算法
- 【数据结构】查找算法:二分查找、顺序查找
- (3) 查找算法 --- 顺序查找 折半查找
- Spring 菜鸟笔记
- codeforces- 82B
- (2)创建一个服务和消息
- 算法<Permutation Sequence>
- Ubuntu常用命令
- 算法-->顺序查找
- 1.用户/执行/文件系统/ls/cd
- GoF23设计模式(0)单例模式Singleton
- 15.Scala多重继承、多重继承构造器执行顺序及AOP实现
- 【codefoces821E】 Okabe and El Psy Kongroo【Dp+矩阵快速幂】
- Android 新手安装Eclipse 启动后的主界面没有出现 SDK manager 的图标
- Python 字符串
- 杭电acm 2588GCD
- 拦截导弹