1. c语言中什么是索引
1.索引表的类型可定义如下:
struct IndexItem
{
IndexKeyType index;
//IndexKeyType为事先定义的索引值类型
int start;
//子表中第一个元素所在的下标位置
int length;
//子表的长度域
};
2.首先根据给定的索引值K1,在索引表上查找出索引值等于K1的索引项,以确定对应子表在主表中的开始位置和长度,然后再根据给定的关键字K2,在对应的子表中查找出
3。关键字等于K2的元素。
设数组A是具有mainlist类型的一个主表,数组B是具有indexlist类型的在主表A上建立的一个索引表,m为索引表B的实际长度,即所含的索引项的个数,K1和K2分别为给定
带查找的索引值和关键字,并假定每个子表采用顺序存储,则索引查找算法为:
int Indsch(mainlist A, indexlist B, int m, IndexKeyType K1, KeyType K2)
{//利用主表A和大小为 m 的索引表B索引查找索引值为K1,关键字为K2的记录
//返回该记录在主表中的下标位置,若查找失败则返回-1
int i, j;
for (i = 0; i < m; i++)
if (K1 == B[i].index)
break;
if (i == m)
return -1; //查找失败
j = B[i].start;
while (j < B[i].start + B[i].length)
{
if (K2 == A[j].key)
break;
else
j++;
}
if (j < B[i].start + B[i].length)
return j; //查找成功
else
return -1; //查找失败
}
2. C语言里实现一张索引表
二维数组,或者枚举
例如枚举:
typedef enum {
a,
b,
c,
d
} list_enum;
这样当调用这个枚举的a时就等于0了,简单吧!
3. 如何用C语言进行索引排序
问题解决了吗,也也想知道方法
4. c语言中索引表是什么
顾名思义 是类似“目录”的东西 在c语言中可能是数组, 每个元素都是对应的“结构体”(广义)指针
5. 高手呀~~能不能写一个程序代码,用C语言实现 索引顺序查找算法。
int IdxSearch(IDX I,int m,SeqList R,int n,KeyType k)
{
int low=0,high=m-1,mid,i;
int b=n/m; /*b为每块的记录个数*/
while (low<=high) /*在索引表中进行二分查找,找到的位置存放在low中*/
{
mid=(low+high)/2;
if (I[mid].key>=k)
high=mid-1;
else
low=mid+1;
}
if (low<m) /*在索引表中查找成功后,再在线性表中进行顺序查找*/
{
i=I[low].link;
while (i<=I[low].link+b-1 && R[i].key!=k) i++;
if (i<=I[low].link+b-1)
return i;
else
return -1;
}
return -1;
}
索引表用二分法查找,线性表中是顺序查找,如果都用二分法或者顺序查找,自己改改就好,自己动手了、、、哈哈
6. C语言“索引(从零开始)必须大于或等于零,且小于参数列表的大小”,是什么意思
计算机的内存编号是从零开始编号的,是一种规定。出现这个错误,可能是你的代码执行过程种,索引为负值。
7. C语言文件中怎么对存入文件的数据设置索引,在使用的时候可以按照索引的类别来调用它
你可在写入主体文件数据时,顺便建立索引表写入本文件或另一个文件,可以在读主体数据的文件前,先读取索性表的文件,然后根据索引表指向的位置定位文件流指针读取主体数据文件。
8. c语言怎么索引结构体类型
也许你可以定义一个数组,数组的值是结构体各个成员在结构体中的偏移位置
拓展资料:在C语言中,结构体(struct)指的是一种数据结构,是C语言中聚合数据类型(aggregate data type)的一类。结构体可以被声明为变量、指针或数组等,用以实现较复杂的数据结构。结构体同时也是一些元素的集合,这些元素称为结构体的成员(member),且这些成员可以为不同的类型,成员一般用名字访问。
在C语言中,定义一个结构的一般形式为:struct结构名{//成员表列};
成员表由若干个成员组成,每个成员都是该结构的一个组成部分。对每个成员也必须做类型说明,其形式为:“类型说明符成员名;”。成员名的命名应符合标识符的书写规定。
9. c语言索引搜索如何建立索引表
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<direct.h>
#include<string.h>
#include<io.h>
#include<stdio.h>
#include<iostream>
#include<windows.h>
#include<time.h>
usingnamespacestd;
FILE*p;
voidmd(longlongintm)
{
longlongintshi,fen,miao,hmiao;
hmiao=m%3600000;
m=m/1000;
if(m/3600<24)
{
shi=m/3600;
fen=m/60%60;
miao=m%60;
cout<<endl<<"换算等于"<<shi<<"时:"<<fen<<"分:"<<miao<<"秒:"<<(hmiao-miao*1000)<<"毫秒"<<endl;
}
elseprintf("输入数值太大");
}
classCBrowseDir
{
protected:
charm_szInitDir[_MAX_PATH];
public:
CBrowseDir();
boolSetInitDir(constchar*dir);
boolBeginBrowse(constchar*filespec);
protected:
boolBrowseDir(constchar*dir,constchar*filespec);
virtualboolProcessFile(constchar*filename);
virtualvoidProcessDir(constchar*currentdir,constchar*parentdir);
};
CBrowseDir::CBrowseDir()
{
getcwd(m_szInitDir,_MAX_PATH);
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");
}
boolCBrowseDir::SetInitDir(constchar*dir)
{
if(_fullpath(m_szInitDir,dir,_MAX_PATH)==NULL)
returnfalse;
if(_chdir(m_szInitDir)!=0)
returnfalse;
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");
returntrue;
}
boolCBrowseDir::BeginBrowse(constchar*filespec)
{
ProcessDir(m_szInitDir,NULL);
returnBrowseDir(m_szInitDir,filespec);
}
boolCBrowseDir::BrowseDir(constchar*dir,constchar*filespec)
{
_chdir(dir);
longhFile;
_finddata_tfileinfo;
if((hFile=_findfirst(filespec,&fileinfo))!=-1)
{
do
{
if(!(fileinfo.attrib&_A_SUBDIR))
{
charfilename[_MAX_PATH];
strcpy(filename,dir);
strcat(filename,fileinfo.name);
puts(filename);
fputs(filename,p);
fprintf(p," ");
if(!ProcessFile(filename))
returnfalse;
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
_chdir(dir);
if((hFile=_findfirst("*.*",&fileinfo))!=-1)
{
do
{
if((fileinfo.attrib&_A_SUBDIR))
{
if(strcmp(fileinfo.name,".")!=0&&strcmp
(fileinfo.name,"..")!=0)
{
charsubdir[_MAX_PATH];
strcpy(subdir,dir);
strcat(subdir,fileinfo.name);
strcat(subdir,"\");
ProcessDir(subdir,dir);
if(!BrowseDir(subdir,filespec))
returnfalse;
}
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
returntrue;
}
boolCBrowseDir::ProcessFile(constchar*filename)
{
returntrue;
}
voidCBrowseDir::ProcessDir(constchar
*currentdir,constchar*parentdir)
{
}
classCStatDir:publicCBrowseDir
{
protected:
longlongintm_nFileCount;
longlongintm_nSubdirCount;
public:
CStatDir()
{
m_nFileCount=m_nSubdirCount=0;
}
intGetFileCount()
{
returnm_nFileCount;
}
intGetSubdirCount()
{
returnm_nSubdirCount-1;
}
protected:
virtualboolProcessFile(constchar*filename)
{
m_nFileCount++;
returnCBrowseDir::ProcessFile(filename);
}
virtualvoidProcessDir
(constchar*currentdir,constchar*parentdir)
{
m_nSubdirCount++;
CBrowseDir::ProcessDir(currentdir,parentdir);
}
};
intmain()
{
intDiskCount=0;
DWORDDiskInfo=GetLogicalDrives();
while(DiskInfo)
{
if(DiskInfo&1)
{
++DiskCount;
}
DiskInfo=DiskInfo>>1;
}
cout<<"逻辑磁盘数量:"<<DiskCount<<endl;
intDSLength=GetLogicalDriveStrings(0,NULL);
char*DStr=newchar[DSLength];
GetLogicalDriveStrings(DSLength,(LPTSTR)DStr);
intDType;
intsi=0;
BOOLfResult;
;
unsignedlonglongintTotalBytes;
;
;
intg=0,k=0;
charname[100];
for(inti=0;i<DSLength/4;++i)
{
chardir[5]={DStr[si],':','\'};
cout<<dir;
DType=GetDriveType(DStr+i*4);
if(DType==DRIVE_FIXED)
{
cout<<"硬盘";
name[k]=DStr[si];
k++;
g++;
}
elseif(DType==DRIVE_CDROM)
{
cout<<"光驱";
}
elseif(DType==DRIVE_REMOVABLE)
{
cout<<"可移动式磁盘";
}
elseif(DType==DRIVE_REMOTE)
{
cout<<"网络磁盘";
}
elseif(DType==DRIVE_RAMDISK)
{
cout<<"虚拟RAM磁盘";
}
elseif(DType==DRIVE_UNKNOWN)
{
cout<<"未知设备";
}
fResult=GetDiskFreeSpaceEx(dir,(PULARGE_INTEGER)&i64FreeBytesToCaller,(PULARGE_INTEGER)&i64TotalBytes,(PULARGE_INTEGER)&i64FreeBytes);
if(fResult)
{
if((i64TotalBytes/1024/1024)>1024)
cout<<"磁盘大小:"<<(float)i64TotalBytes/1024/1024/1024<<"GB";
else
cout<<"磁盘大小:"<<(float)i64TotalBytes/1024/1024<<"MB";
if((i64FreeBytesToCaller/1024/1024)>1024)
cout<<"剩余空间:"<<(float)i64FreeBytesToCaller/1024/1024/1024<<"GB";
else
cout<<"剩余空间:"<<(float)i64FreeBytesToCaller/1024/1024<<"MB";
}
else
{
cout<<"设备未准备好或启用了系统加密!";
}
if(!fResult)
{
k--;
}
cout<<endl;
si+=4;
}
cout<<"共有硬盘"<<g<<"块"<<endl;
g=k+1;
cout<<"共有未加密的硬盘"<<g<<"块"<<endl;
cout<<"正在启动索引程序"<<endl;
inti;
p=fopen("list.txt","a+");
if(g==1)
{
cout<<"您只有一个c盘"<<endl;
cout<<"检测C盘可能会让程序崩溃"<<endl;
}
clock_tstart,finish;
start=clock();
for(i=1;i<g;i++)
{
fprintf(p,"%c盘内的文件如下 ",name[i]);
charbuf[6]={name[i],':','\'};
CStatDirstatdir;
statdir.SetInitDir(buf);
statdir.BeginBrowse("*.*");
fprintf(p,"文件总数:%d 子目录总数:%d ",statdir.GetFileCount(),statdir.GetSubdirCount());
printf("文件总数:%d 子目录总数:%d ",statdir.GetFileCount(),statdir.GetSubdirCount());
}
cout<<"全部完成"<<endl;
finish=clock();
cout<<"用时"<<(finish-start)<<"毫秒";
md(finish-start);
return0;
}
10. C语言上的问题编写一个函数,返回一个double数组中存储的最大数值的索引,并在一个简单的程序中测试。
你的程序有问题,不是简单的语句错误,你的思路错了,你看一下你的程序根本就不是在找最大值的索引,而是在找第一次出现数字变小的那个数字的索引,这样说有点模糊,举几个例子,来说明一下你的程序是在干什么。例如,你要是搜索序列1,2,3,1,4,5,6那么会返回2,因为第二个数字(也就是3),开始第一次下降,因为下一个数字为1,比3小,所以你的程序就开始返回了,并且返回2。再举个例子,例如搜索序列2,4,6,8,5,7,9那么你的程序就会返回索引3,因为第三个数字(即8),开始出现下降,下一个数字为5,比8小,所以你的程序就开始返回了,并且返回值为8的索引3(即第3个数字)。 不知道你是否明白了,其实你的意思是想找出最大的那个,就只要max对所有的数字遍历一下,并且不断更新为更大的值,而且用max1紧随其后标记更新的最大值的索引,max1=i;而将return max1;放到调用函数的最后面一句就可以了。 如果你还是不太明白可以追问我,要是你真的明白了,可以做一下选择排序的题目,会让你加深理解的