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;放到調用函數的最後面一句就可以了。 如果你還是不太明白可以追問我,要是你真的明白了,可以做一下選擇排序的題目,會讓你加深理解的