Flight information query and retrieval based on C language

  • 2020-06-01 10:37:58
  • OfStack

In this paper, the example for you to share the flight information query and retrieval of the specific code, for your reference, the specific content is as follows


#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[7]; // The station  
 char end[7]; // The terminal  
 char sche[12]; // The flight phase  
 char time1[5]; // Is the departure time  
 char time2[5]; // Time of arrival  
 char mode1[3]; // models  
 int price;  // The fare  
}InfoType;  // Flight record type  

typedef struct{
 KeyType keys[keylen];// The keyword  
 InfoType others;
 int next;
}SLNode;  // Static list node type 

typedef struct{
 SLNode sl[MaxSpace];// Static linked list, s1[0] As the head node  
 int keynum;  // Record the current number of keyword characters  
 int length;  // The current table long  
}SLList;  // Static list type  

typedef int ArrType_n[RADIX_n];  //10 Array of numeric Pointers  

typedef int ArrType_c[RADIX_c] ; //26 An array of letter Pointers  

void Display(SLList,int i);  // Declare output function  


/*1 The number character assignment function */
void Distribute(SLNode *s1,int i,ArrType_n f,ArrType_n e) 
{
 int j,p;
 for(j=0 ; j<RADIX_n ; j++)
 {
 // Each subtable is set to an empty table 
 f[j] =0;
 e[j]=0;
 }
 for(p=s1[0].next;p;p=s1[p].next)
 {
 j=s1[p].keys[i]%48; // Converts numeric characters to numeric Numbers of the corresponding numeric type 
 if(!f[j]) 
  f[j]=p;
 else
  s1[e[j]].next=p;
  e[j]=p;  // will p Point to the node input to the first j A word in the table  
 }
}


/*1 The number character collection function */
void Collect(SLNode *s1,int i,ArrType_n f,ArrType_n e)
{
 int j,t;
 for(j=0;!f[j];j++);  // Find the first 1 A non-empty subset  
 s1[0].next=f[j]; //s1[0].next Pointing to the first 1 Not in a null subtable 1 A node  
 t=e[j];
 while(j<RADIX_n-1)
 {
 for(j=j+1;j<RADIX_n-1 && !f[j];j++); // To find the 1 A non-empty subtable  
 if(f[j])
 {
  s1[t].next=f[j]; // Join two non-empty subtables  
  t=e[j];
 }
 s1[t].next=0;
 }
}


/*1 Alphanumeric character assignment function */
void Distribute_c(SLNode *s1,int i,ArrType_c f,ArrType_c e)
{
 int j,p;
 for(j=0;j<RADIX_c;j++)
 {
 // Each subclass table is set to empty 
 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;
 }
}


/*1 The alphabetic character collection function */
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(j<RADIX_c-1)
 {
 for(j=j+1;j<RADIX_c-1 && !f[j];j++)
  if(f[j])
  {
  s1[t].next=f[j];
  t=e[j];
  }
 }
 s1[t].next=0;
}


/* Chain radix sort function */
SLList 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;  //0 Cell number only holds Pointers, not content  
 L.sl[L.length].next=0; // The ordinary linear table is transformed into a static linked list  
 for(i=L.keynum-1;i>=2;i--)
 {
  // According to the lowest order of priority to the keyword allocation and collection, first do low 4 Bit digit part 
  Distribute(L.sl,i,fn,en) ;
  Collect(L.sl,i,fn,en);
 }
 for(i=1;i>=0;i--)
 {
  // For high 2 Bit capital letters are assigned and collected 
  Distribute_c(L.sl,i,fc,ec) ;
  Collect_c(L.sl,i,fc,ec);
 }
 return L;
}//RadixSort 


/* Reorganize the static list by pointer chain */
SLList Arrange(SLList L)
{
 int p,q,i;
 SLNode temp;
 p=L.sl[0].next;
 for(i=1;i<=L.length;i++)
 {
 while(p<i)   //************ There's a problem here ************* 
  p=L.sl[p].next;
  q=L.sl[p].next;
  if(p!=i)
  {
  temp=L.sl[p]; // Exchange record 
  L.sl[p]=L.sl[i]; // Exchange record 
  L.sl[i]=temp; // Exchange record 
  L.sl[i].next=p;
  }
 p=q;
 }
 return L;
}


/* Implementation of the lookup algorithm */
int BinSearch(SLList L,KeyType key[]) //2 Sublookup function  
{
 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


/* Sequential lookup function */
void SeqSearch(SLList L,KeyType key[],int i) 
{
 int j,k,m=0;
 for(j=1;j<L.length;j++)
 {
 switch(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(" This flight information is not available. It may be a typo: \n"); 
}


/* I/o function */
void Display(SLList L,int i)
{
 if(i==0) printf(" This flight information is not available. It may be a typo: \n");
 else{
 printf(" Flight no.   The station   The terminal   The flight phase   Is the departure time   Time of arrival   models   The fare \n");
 printf("%s,%s,%s,%s,%s,%s,%s,%d\n",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);
 } 
}


/* Query retrieval menu controller */
void serachcon(SLList L)
{
 int i=1,k;
 KeyType key[keylen],k1[4];
 while(i>=1 && i<=5){
 printf("*********************************\n");
 printf("");
 printf("*  Flight information inquiry system  *\n");
 printf("*********************************\n");
 printf("*  1. navigation   class   No.   *\n");
 printf("*  2. since   point   standing   *\n");
 printf("*  3. The final   point   standing   *\n");
 printf("*  4. Is the departure time   *\n");
 printf("*  5. Time of arrival   *\n");
 printf("*  0. Log out   *\n");
 printf("*********************************\n");
 printf("   Please select a (1-5)  \n");
 scanf("%d",&i);
 switch(i){
  case 1:
  printf(" Enter the flight number to query (in uppercase) : ");
  scanf("%s",key);
  k=BinSearch(L,key);
  Display(L,k);
  break;

  case 2:
  printf(" Enter the name of the flight departure station to be queried: ");
  scanf("%s",key);
  SeqSearch(L,key,i);
  break;

  case 3:
  printf(" Enter the name of the flight terminal to be queried: ");
  scanf("%s",key);
  SeqSearch(L,key,i);
  break;

  case 4:
  printf(" Please enter the departure time of the flight to be inquired: ");
  scanf("%s",k1);
  SeqSearch(L,k1,i);
  break;

  case 5:
  printf(" Enter the flight arrival time to be queried: "); 
  scanf("%s",k1);
  SeqSearch(L,k1,i);
  break;

  case 0:
  printf(" Exit the program , Good bye! \n");
  return ; 
 }
 }
}


/* Enter the flight log function */
SLList InputData(SLList L)
{
 int i=++L.length;
 char yn='y';
 while(yn=='y' || yn=='Y')
 {
 printf(" Flight no.   The station   The terminal   The flight phase   Is the departure time   Time of arrival   models   The fare \n");
 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(" Continue typing? y/n:");
 getchar();
 scanf("%c",&yn);
 }
 L.length=i-1;
 return L; 
}


/* The main function */
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);  // Enter flight records  
 L=RadixSort(L);  // Radix sort  
 L=Arrange(L); 
 serachcon(L);  // Call the query function  
}

For more information, please refer to the topic "management system development".


Related articles: