當前位置:編程學習大全網 - 源碼下載 - 鏈式源代碼

鏈式源代碼

void distribute(slnode *sl,int i,arrtype_n f,arrtype_n e)

{

int j,p;

for(j = 0;j & ltradix _ n;j++)

{

f[j]= e[j]= 0;

}

for(p=sl[0])。接下來;p;p=sl[p]。下壹個)

{

j=sl[p]。keys[I]% 48;

如果(!f[j])

f[j]= p;

其他

sl[e[j]]。next = p;

e[j]= p;

}

}

void collect(slnode *sl,int i,arrtype_n f,arrtype_n e)

{

int j,t;

for(j = 0;!f[j];j++);

sl[0]。next = f[j];

t = e[j];

while(j & lt;radix_n-1)

{

for(j = j+1;j & lt基數n-1 & amp;& amp!f[j];j++);

if(f[j])

{

sl[t]。next = f[j];

t = e[j];

}

}

sl[t]。next = 0;

}

void distribute_c(slnode *sl,int i,arrtype_c f,arrtype_c e)

{

int j,p;

for(j = 0;j & ltradix _ c;j++)

{

f[j]= e[j]= 0;

}

for(p=sl[0])。接下來;p;p=sl[p]。下壹個)

{

j=sl[p]。keys[I]% 65;

如果(!f[j])

f[j]= p;

其他

sl[e[j]]。next = p;

e[j]= p;

}

}

void collect_c(slnode *sl,int i,arrtype_c f,arrtype_c e)

{

int j,t;

for(j = 0;!f[j];j++);

sl[0]。next = f[j];

t = e[j];

while(j & lt;radix_c-1)

{

for(j = j+1;j & lt基數_ c-1 & amp;& amp!f[j];j++);

if(f[j])

{

sl[t]。next = f[j];

t = e[j];

}

}

sl[t]。next = 0;

}

void radix sort(sl list & amp;L)// chain

{

int I;

arrtype_n fn,en;

arrtype_c fc,EC;

for(I = 0;我& lt長度;i++)

l.sl[i]。next = I+1;

長度。next = 0;

for(I = l . keynum-1;我& gt=2;我-)

{

distribute(l.sl,I,fn,en);

collect(l.sl,I,fn,en);

}

for(I = 1;我& gt=0;我-)

{

distribute_c(l.sl,I,fc,EC);

collect_c(l.sl,I,fc,EC);

}

}

void arrange(sl list & amp;L)//重新排列

{

int p,q,I;

slnode溫度;

p=l.sl[0]。接下來;

for(I = 1;我& lt長度;i++)

{

while(p & lt;我)

p=l.sl[p]。接下來;

q=l.sl[p]。接下來;

如果(p!=i)

{

temp = l . sl[p];

l . sl[p]= l . sl[I];

l . sl[I]= temp;

l.sl[i]。next = p;

}

p = q;

}

}

int binsearch(sllist l,keytype key[])

{

int低、高、中;

低= 1;

高=l .長度;

while(low & lt;=高)

{

mid=(低+高)/2;

if(strcmp(key,l.sl[mid])。keys)==0)

返回mid

else if(strcmp(key,l.sl[mid])。鍵)& lt0)

高=中1;

其他

低= mid+1;

}

返回0;

}

void seqsearch(sllist l,keytype key[],int i)

{

int j,k,m = 0;

printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

Printf("*航班號、始發站、終點站、航段、出發時間、到達時間、機型票價* \ n ");

for(j = 1;j & lt=l .長度;j++)

{

開關(壹)

{

情況二:k=strcmp(key,l . sl[j]. others . start);打破;

案例三:k=strcmp(key,l . sl[j]. others . end);打破;

情況四:k=strcmp(key,l . sl[j]. others . time 1);打破;

情況5:k=strcmp(key,l . sl[j]. others . time 2);打破;

}

如果(k==0)

{

m = 1;

printf(" * %-8s %-7s %-6s %-11s %-9s %-7s %-5s % 4d * \ n ",l.sl[j]。keys,l.sl[j].others.start,l.sl[j].others.end,l.sl[j].others.sche,l.sl[j].others.time1,l.sl[j].others.time2,l.sl[j].others.model,l . sl[j]. others . price);

}

}

如果(m==0)

Printf("*沒有航班信息,可能是輸入錯誤* \ n ");

printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

}

無效搜索圖標(列表l)

{

key type key[key len];

int i=1,k;

while(I & gt;=1。& amp我& lt=5)

{ printf(" \ n * * * * * * * * * * * * * * * * * * * * \ n ");

Printf(" *航班信息查詢系統* \ n ");

printf(" * * * * * * * * * * * * * * * * * * * \ n ");

Printf(" * 1。航班號* \ n ");

Printf(" * 2。起點站* \ n ");

Printf(" * 3。terminal * \ n ");

Printf(" * 4。出發時間* \ n”);

Printf(" * 5。到達時間* \ n ");

Printf(" * 0。退出系統* \ n ");

printf(" * * * * * * * * * * * * * * * * * * * \ n ");

Printf("請選擇(0-5):");

scanf("%d ",& ampI);

printf(" \ n ");

開關(壹)

{case 1:printf("輸入要查詢的航班號(字母要大寫):");

scanf("%s ",key);

k=binsearch(l,key);

printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

如果(k==0)

Printf("*沒有這個航班的信息,可能是輸入錯誤!* \ n ");

其他

{

Printf("*航班號,出發時間,到達時間,機型票價* \ n ");

printf(" * %-8s %-7s %-6s %-11s %-9s %-7s %-5s % 4d * \ n ",l.sl[k]。keys,l.sl[k].others.start,l.sl[k].others.end,l.sl[k].others.sche,l.sl[k].others.time1,l.sl[k].others.time2,l.sl[k].others.model,l . sl[k]. others . price);

}

printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");

打破;

案例二:printf("輸入要查詢的航班始發站名稱:");

scanf("%s ",key);

seqsearch(l,key,I);

打破;

案例三:printf("輸入要查詢的航班始發站名稱:");

scanf("%s ",key);

seqsearch(l,key,I);

打破;

案例四:printf("輸入要查詢的航班始發站名稱:");

scanf("%s ",key);

seqsearch(l,key,I);

打破;

案例五:printf("輸入要查詢的航班始發站名稱:");

scanf("%s ",key);

seqsearch(l,key,I);

打破;

案例0:printf(" \ n \ n \ n再見n \ n ");

}

}

}

void input data(sl list & amp;l)

{

int I = ++ l . length;

char yn = ' y

while(yn=='y'||yn=='Y ')

{

Printf("航班號,出發時間,到達時間,機型票價\ n ");

scanf(" % s % s % s % s % s % s % s % s % d ",l.sl[i]。keys,l.sl[i].others.start,l.sl[i].others.end,l.sl[i].others.sche,l.sl[i].others.time1,l.sl[i].others.time2,l.sl[i].others.model,& ampl . sl[I]. others . price);

++ I;getchar();

radix sort(l);

排列(l);

Printf("繼續打字?y/n:");

scanf("%c ",& ampyn);

}

l . length = I-1;

}

void main()

{

sl list l;

l . keynum = 6;

l .長度= 0;

輸入數據(l);

searchcon(l);

}

  • 上一篇:蛋白質—能量營養不良表現
  • 下一篇:求魔獸世界改模型的插件 是改坐騎和裝備模型的
  • copyright 2024編程學習大全網