您的位置首页生活百科

求C语言编程(航班信息查询与检索)

求C语言编程(航班信息查询与检索)

的有关信息介绍如下:

求C语言编程(航班信息查询与检索)

#include "stdio.h"#include "malloc.h"#include "string.h"#define MAXN 100typedef struct{char hour[MAXN];char minute[MAXN];} time;typedef struct node{char number[MAXN]; //航班号time start; //起飞时间time end; //到达时间char start_station[MAXN]; //起点站char end_station[MAXN]; //终点站char type[MAXN]; //飞机型号char price[MAXN]; //票价struct node*link;}NODE;NODE *create_link_list(int n){int i;NODE *head,*p,*q;if(n==0)return(NULL);head=(NODE*)malloc(sizeof(NODE));for(i=0;i number[i]='\0';head->start.hour[i]='\0';head->start.minute[i]='\0';head->end.hour[i]='\0';head->end.minute[i]='\0';head->start_station[i]='\0';head->end_station[i]='\0';head->type[i]='\0';head->price[i]='\0';}p=head;for(i=1;i number));printf("请输入起飞时间(时 分):");scanf("%s %s",&(p->start.hour),&(p->start.minute));printf("请输入达到时间(时 分):");scanf("%s %s",&(p->end.hour),&(p->end.minute));printf("请输入起点站 终点站:");scanf("%s %s",&(p->start_station),&(p->end_station));printf("请输入飞机型号:");scanf("%s",&(p->type));printf("请输入票价:");scanf("%s",&(p->price));printf("\n");q=(NODE*)malloc(sizeof(NODE));p->link=q;p=q;}printf("请输入航班号:");scanf("%s",&(p->number));printf("请输入起飞时间(时 分):");scanf("%s %s",&(p->start.hour),&(p->start.minute));printf("请输入达到时间(时 分):");scanf("%s %s",&(p->end.hour),&(p->end.minute));printf("请输入起点站 终点站:");scanf("%s %s",&(p->start_station),&(p->end_station));printf("请输入飞机型号:");scanf("%s",&(p->type));printf("请输入票价:");scanf("%s",&(p->price));printf("\n");getchar();p->link=NULL;return(head);}void insert(NODE **p_head,NODE *q){NODE *p;if(*p_head==NULL)*p_head=q;else{p=*p_head;while(p!=NULL&&p->link!=NULL)p=p->link;p->link=q;}}unsigned int countit(NODE* n)//计算链表长度{ unsigned int counti = 0; while(n!=NULL) counti++,n=n->link; return counti;}NODE* getindex(NODE* head, int num);NODE* getindex(NODE* head, int num)//取得index为num 的节点!{ if(num<0 || num>countit(head)) return NULL; NODE* rn = head; while(--num>0) rn = rn->link; return rn;}int binSearch(NODE* n,char *strinput,int low, int high)// 二分查找{ int i; int middle = (high+low)/2; if (high < low) return 0; if ((i=strcmp(strinput, n->number)) <0) high= middle; else if (i > 0) low = middle; else { i = middle; return i; } binSearch(getindex(n,middle),strinput,low,high);}int bisect(char a[],int n,char s[MAXN])//二分查找{int i,j,m;i=0;j=n-1;while(i <=j){m=(i+j)/2;}return(-1);}NODE *search1(NODE *head,char v[MAXN])//起点站顺序查找{for(;head!=NULL&&strcmp(head->start_station,&v[0]);head=head->link);return(head);}NODE *search2(NODE *head,char w[MAXN])//到达站顺序查找{for(;head!=NULL&&strcmp(head->end_station,&w[0]);head=head->link);return(head);}NODE *search3(NODE *head,char x[MAXN],char y[MAXN])//起飞时间顺序查找{for(;head!=NULL&&(strcmp(head->start.hour,&x[0]) || strcmp(head->start.minute,&y[0]));head=head->link);return(head);}NODE *search4(NODE *head,char t[MAXN],char u[MAXN])//到达时间顺序查找{for(;head!=NULL&&(strcmp(head->end.hour,&t[0]) || strcmp(head->end.minute,&u[0]));head=head->link);return(head);}void output(NODE *p){ while(p!=NULL) { printf("航班信息:\n"); printf("航班号:%s\n",p->number); printf("起飞时间:%s点%s分,",p->start.hour,p->start.minute); printf("到达时间:%s点%s分\n",p->end.hour,p->end.minute); printf("起点站:%s,",p->start_station); printf("到达站:%s\n",p->end_station); printf("飞机型号:%s ",p->type); printf("票价:%s元\n\n",p->price); p=p->link; }}NODE *rank( NODE *head){ NODE *q=0,*p=0,*t,*h1; h1=head->link; head->link=NULL; while(h1!=NULL) { t=h1; h1=h1->link; p=head; q=head; while( p!=NULL && strcmp(t->number, p->number)>0 ) { q=p; p=p->link; } if(q == p) { t->link=p; head=t; } else { t->link=p; q->link=t; } } return head;}int main(int argc, char* argv[]){ NODE *p,*q,*r; int a,b,i,j,n; int count=0; char o[MAXN]; char s[MAXN]; char v[MAXN]; char w[MAXN]; char x[MAXN]; char y[MAXN]; char t[MAXN]; char u[MAXN]; for(i=0;i