⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 折半查找.bak

📁 常用算法
💻 BAK
字号:
clear
dime a(10)
n=10
for i=1 to 10
   a(i)=int(rand()*100)
   ??a(i)
 next 
*排序 
 for i=1 to n-1
    for j=n to i+1 step -1
      if a(j)<a(j-1)
       t=a(j)
       a(j)=a(j-1)
       a(j-1)=t
       endif
   next j
   next i
   ?"sort:"
   for i=1 to n
    ?? a(i)
   next i
  *折半查找
  input "输入要查找的数:"to x
  l=1
  h=10
  do while l<=h
    m=int((l+h)/2)
    if a(m)=x then 
     exit 
    else
      if a(m)>x then
         h=m-1
      else 
         l=m+1
       endif
    endif
    enddo
    if l<=h then 
    ?"找到",M,a(m)
    else
     ?"没有找到!"
     endif
             

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -