 数据结构课程设计 航班 我的源码
// HBXX.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <string.h> #define maxspace 100 #define keylen 7 #define radix_n 10 #define radix_c 26 typedef char keytype; typedef struct { char start[6]; char end[6]; char sche[10]; char time1[5]; char time2[5]; char model[4]; int price; }infotype; typedef struct { keytype keys[keylen]; infotype others; int next; }slnode; typedef struct { slnode sl[maxspace]; int keynum; int length; }sllist; typedef int arrtype_n[radix_n]; typedef int arrtype_c[radix_c];
void distribute(slnode *sl,int i,arrtype_n f,arrtype_n e) { int j,p; for(j=0;j<radix_n;j++) { f[j]=e[j]=0; } for(p=sl[0].next;p;p=sl[p].next) { j=sl[p].keys[i]%48; if(!f[j]) f[j]=p; else 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<radix_n-1) { for(j=j+1;j<radix_n-1&&!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<radix_c;j++) { f[j]=e[j]=0; } for(p=sl[0].next;p;p=sl[p].next) { j=sl[p].keys[i]%65; if(!f[j]) f[j]=p; else 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<radix_c-1) { for(j=j+1;j<radix_c-1&&!f[j];j++); if(f[j]) { sl[t].next=f[j]; t=e[j]; } } sl[t].next=0; }
void radixsort(sllist &l)//链式 { int i; arrtype_n fn,en; arrtype_c fc,ec; for(i=0;i<l.length;i++) l.sl[i].next=i+1; l.sl[l.length].next=0; for(i=l.keynum-1;i>=2;i--) { distribute(l.sl,i,fn,en); collect(l.sl,i,fn,en); } for(i=1;i>=0;i--) { distribute_c(l.sl,i,fc,ec); collect_c(l.sl,i,fc,ec); } }
|