C 언어 기반의 항공편 정보 조회 및 검색

18211 단어 C 언어
항공편 정보의 조회와 검색
#include
#include

#define MaxSpace 100
#define keylen 7
#define RADIX_n 10
#define RADIX_c 26

typedef char KeyType;
typedef struct{
    char start[7];      //    
    char end[7];        //    
    char sche[12];      //    
    char time1[5];      //     
    char time2[5];      //     
    char mode1[3];      //   
    int price;          //   
}InfoType;              //       

typedef struct{
    KeyType keys[keylen];//    
    InfoType others;
    int next;
}SLNode;                //        

typedef struct{
    SLNode sl[MaxSpace];//    ,s1[0]     
    int keynum;         //            
    int length;         //     
}SLList;                //       

typedef int ArrType_n[RADIX_n];         //          

typedef int ArrType_c[RADIX_c] ;        //26        

void Display(SLList,int i);             //       


/*          */
void Distribute(SLNode *s1,int i,ArrType_n f,ArrType_n e) 
{
    int j,p;
    for(j=0 ; j//       
        f[j] =0;
        e[j]=0;
    }
    for(p=s1[0].next;p;p=s1[p].next)
    {
        j=s1[p].keys[i]%48; //                  
        if(!f[j]) 
            f[j]=p;
        else
            s1[e[j]].next=p;
            e[j]=p;         // p         j     
    }
}


/*          */
void Collect(SLNode *s1,int i,ArrType_n f,ArrType_n e)
{
    int j,t;
    for(j=0;!f[j];j++);         //         
        s1[0].next=f[j];        //s1[0].next                
    t=e[j];
    while(j1)
    {
        for(j=j+1;j1 && !f[j];j++);    //         
        if(f[j])
        {
            s1[t].next=f[j];    //         
            t=e[j];
        }
        s1[t].next=0;
    }
}


/*          */
void Distribute_c(SLNode *s1,int i,ArrType_c f,ArrType_c e)
{
    int j,p;
    for(j=0;j//       
        f[j]=0;
        e[j]=0;
    }
    for(p=s1[0].next;p!=0;p=s1[p].next)
    {
        j=s1[p].keys[i] % 65;
        if(!f[j])
            f[j]=p;
        else
            s1[e[j]].next=p;
        e[j]=p;
    }
}


/*          */
void Collect_c(SLNode *s1,int i,ArrType_c f,ArrType_c e)
{
    int j,t;
    for(j=0;!f[j];j++);
        s1[0].next=f[j];
    t=e[j];
    while(j1)
    {
        for(j=j+1;j1 && !f[j];j++)
            if(f[j])
            {
                s1[t].next=f[j];
                t=e[j];
            }
    }
    s1[t].next=0;
}


/*        */
SLList RadixSort(SLList L)
{
    int i;
    ArrType_n fn,en;
    ArrType_c fc,ec;
    for(i=0;i1;           //0        ,      
        L.sl[L.length].next=0;      //                 
        for(i=L.keynum-1;i>=2;i--)
        {
            //                    ,   4     
            Distribute(L.sl,i,fn,en) ;
            Collect(L.sl,i,fn,en);
        }
        for(i=1;i>=0;i--)
        {
            //    2            
            Distribute_c(L.sl,i,fc,ec) ;
            Collect_c(L.sl,i,fc,ec);
        }
    return L;
}//RadixSort 


/*            */
SLList Arrange(SLList L)
{
    int p,q,i;
    SLNode temp;
    p=L.sl[0].next;
    for(i=1;i<=L.length;i++)
    {
        while(p//************     ************* 
            p=L.sl[p].next;
            q=L.sl[p].next;
            if(p!=i)
            {
                temp=L.sl[p];       //    
                L.sl[p]=L.sl[i];    //    
                L.sl[i]=temp;       //    
                L.sl[i].next=p;
            }
        p=q;
    }
    return L;
}


/*       */
int BinSearch(SLList L,KeyType key[])       //       
{
    int low,high,mid;
    low=1;
    high=L.length-1;
    while(low<=high)
    {
        mid=(low+high)/2;
        if(strcmp(key,L.sl[mid].keys)<0)
            return mid;
        else
            if(strcmp(key,L.sl[mid].keys)<0)
                high=mid-1;
            else
                low=mid+1;
    }
    return 0;
}//BinSearch


/*      */
void SeqSearch(SLList L,KeyType key[],int i) 
{
    int j,k,m=0;
    for(j=1;jswitch(i){
            case 2: k=strcmp(key,L.sl[j].others.start); break;
            case 3: k=strcmp(key,L.sl[j].others.end); break;
            case 4: k=strcmp(key,L.sl[j].others.time1); break;
            case 5: k=strcmp(key,L.sl[j].others.time2); break;
        }
        if(k==0){ m=1; Display(L,j); }
    }
    if(m==0) printf("      ,       :
"
); } /* */ void Display(SLList L,int i) { if(i==0) printf(" , :
"
); else{ printf("
"
); printf("%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.mode1, L.sl[i].others.price); } } /* */ void serachcon(SLList L) { int i=1,k; KeyType key[keylen],k1[4]; while(i>=1 && i<=5){ printf("*********************************
"
); printf(""); printf("* *
"
); printf("*********************************
"
); printf("* 1. *
"
); printf("* 2. *
"
); printf("* 3. *
"
); printf("* 4. *
"
); printf("* 5. *
"
); printf("* 0. *
"
); printf("*********************************
"
); printf(" (1-5)
"
); scanf("%d",&i); switch(i){ case 1: printf(" ( ):"); scanf("%s",key); k=BinSearch(L,key); Display(L,k); break; case 2: printf(" :"); scanf("%s",key); SeqSearch(L,key,i); break; case 3: printf(" :"); scanf("%s",key); SeqSearch(L,key,i); break; case 4: printf(" :"); scanf("%s",k1); SeqSearch(L,k1,i); break; case 5: printf(" :"); scanf("%s",k1); SeqSearch(L,k1,i); break; case 0: printf(" , !
"
); return ; } } } /* */ SLList InputData(SLList L) { int i=++L.length; char yn='y'; while(yn=='y' || yn=='Y') { printf("
"
); scanf("%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.mode1, &L.sl[i].others.price); ++i; printf(" ?y/n:"); getchar(); scanf("%c",&yn); } L.length=i-1; return L; } /* */ int main(void) { int i; SLList L; L.keynum=6; L.length=0; for(i=1;i<=L.length;i++) Display(L,i); L=InputData(L); // L=RadixSort(L); // L=Arrange(L); serachcon(L); // }

좋은 웹페이지 즐겨찾기