4_31.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
源码类别:

文章/文档

开发平台:

C/C++

  1. # include<iostream.h>
  2. # include<string.h>
  3. void bsearch(char*list[],char obj[],int len)
  4. {
  5. char** low,**high,**mid;
  6. low=list;
  7. high=list+len-1;
  8. while(low<=high)
  9. {
  10. mid=low+(high-low)/2;
  11. if(strcmp(*mid,obj)<0)
  12. low=mid+1;
  13. else if(strcmp(*mid,obj)>0)
  14. high=mid-1;
  15. else 
  16. {cout<<"Success! The sequential number="<<mid-list+1<<endl;
  17.  return;
  18. }
  19. }
  20. cout<<"Unsucess!"<<endl;
  21. }
  22. void main()
  23. {
  24. char*a[10]={"aa","bbb","cccc","ddddd","eeeeee","fffffff"};
  25. for (int i=0;i<6;i++)
  26. cout<<*(a+i)<<" ";
  27. char c[20];
  28. cout<<endl;
  29. cout<<"请输入要查阅的字符串:";
  30. cin>>c;
  31.     char *b;
  32.     b=c;
  33.     void (*s)(char*[],char*,int);
  34.     s=bsearch;
  35.     (*s)(a,c,6);
  36. }