📄 binaryseach.cpp
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int BinarySeach(items,name,n) //二分法查找
struct Data items[]; //要查找的结构体数组的头指针
char name[]; //要查找的关键字
int n; //结构体数组的长度
{
int low,high,mid;
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if((strcmp(items[mid].name,name)==0))
return mid;
else if((strcmp(items[mid].name,name)<0))
low=mid+1;
else high=mid-1;
}
return -1;
}
//冒泡排序法
#include<stdio.h>
#include<string.h>
bubble(strings,count) //冒泡排序函数
char *strings; //要排序的字符串
int count; //字符串的长度
{
register int m,n;
register char s;
for(m=1;m<count;m++)
for(n=count-1;n>=m;--n)
{
if(strings[n-1]>strings[n]]
{//借助s将strings[n-1]和strings[n]交换
s=strings[n-1];
string[n-1]=strings[n];
strings[n]=s;
}
}
}
//伪随机数生成
#include<stdio.h>
#include<stdlib.h>
#include<tim.h>
//利用系统时间寻找随机数,并将前十个随机数显示出来
int main()
{
long time1;
int i,time2;
//获得正确的日历时间
time1=time(NULL);
printf("%ld\n",time1);
time2=(unsigned)time1/2;
printf("%ld\n",time2);
//以系统时间为参数,为即将生成的伪随机数序列设置起点
srand(time2);
//生成十个伪随机数序列
for(i=0;i<10;i++)
printf("%d",rand());
printf("\n");
return 0;
}
//在输出的结果中,第一个数是系统当前的日历时间
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -