#i n c l u d e<c s t d i o> #include <cstdlib>#include <malloc.h>#include <cstring>Road *head = NULL;void SearchByClass(Road *head){time_t a,b;Road *prev,*p,*end,*temp_head;char Run_time[80];int i=0,Class;printf("请输入您所要查找的道路的番号:\n");exit(5);}while(temp_head!=NULL){if(temp_head->stRoadRec.linkid==Class){end=(Road *)malloc(sizeof(Road));printf("#linkid=%d ",temp_head->stRoadRec.LinkID);printf("roadnameflag=%d ",temp_head->stRoadRec.roadnameflag);printf("brunch=%d ",temp_head->stRoadRec.brunch);i++;}temp_head=temp_head->next;}end->next=NULL;p ->next = NULL;if(i>=5){save(prev);}{Road *prev,*p,*end,*temp_head;char Run_time[80];int i=0,LinkId;printf("请输入您所要查找的道路的ID:\n");scanf("%d",&LinkId);prev=p=(Road *)malloc(sizeof(Road));//创建一个结点a=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&a));end=(Road *)malloc(sizeof(Road));printf("#linkid=%d",temp_head->stRoadRec.LinkID);printf("roadnameflag=%d",temp_head->stRoadRec.roadnameflag);printf("brunch=%d",temp_head->stRoadRec.brunch);printf("dispclass=%d",temp_head->stRoadRec.linkid);printf("roadname=%s#\n",temp_head->stRoadRec.roadname);p->stRoadRec.LinkID=temp_head->stRoadRec.LinkID;p->stRoadRec.roadnameflag=temp_head->stRoadRec.roadnameflag;if(i>=5){save(prev);printf("查询结果数大于5,已保存至SearchResult.txt\n");}b=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&b));printf("本次查找用时%d 秒.\n",b-a);}{scanf("%s",Name);prev=p=(Road *)malloc(sizeof(Road));//创建一个结点a=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&a));temp_head = head;if(temp_head == NULL){printf("无数据源");printf("dispclass=%d",temp_head->stRoadRec.linkid);printf("roadname=%s#\n",temp_head->stRoadRec.roadname);p->stRoadRec.LinkID = temp_head->stRoadRec.LinkID;p->stRoadRec.roadnameflag = temp_head->stRoadRec.roadnameflag;p->stRoadRec.brunch = temp_head->stRoadRec.brunch;p->stRoadRec.linkid = temp_head->stRoadRec.linkid;p->stRoadRec.roadname = temp_head->stRoadRec.roadname;p->next=end;}b=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&b));printf("本次查找用时%d 秒.\n",b-a);}void updata(Road*head){FILE*pp;{printf("文件创建失败\n");exit(1);}//判断文件是否创建成功//p1=head;if(p1==NULL){printf("空指针\n");a=time(NULL);strcpy(filename,"update.dat");infile=fopen("jilu.txt","w");fscanf(infile,"%d%s",&a,&filename);//将时间和update.dat都写入文件中//outfile=fopen("jilu.txt","r");if(outfile==NULL)exit(1);fprintf(outfile,"%s",filename);//将文件中的内容读出来作为文件名////}printf("文件更新中...\n");printf("文件更新成功\n");fclose(ppp);//文件更新完毕,将排序后的内容写入文本文件和二进制文件中//}void SearchByBruch(Road *head) {time_t a,b;temp_head = head;if(temp_head == NULL){printf("无数据源");system("pause");exit(4);}while(temp_head!=NULL)p->stRoadRec.LinkID=temp_head->stRoadRec.LinkID;p->stRoadRec.roadnameflag=temp_head->stRoadRec.roadnameflag;p->stRoadRec.brunch=temp_head->stRoadRec.brunch;p->stRoadRec.linkid=temp_head->stRoadRec.linkid;p->stRoadRec.roadname = temp_head->stRoadRec.roadname;p->next = end;p = p->next;i++;}b=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&b));printf("本次查找用时%d 秒.\n",b-a);}Road* readfile(void){FILE *fp;fp = fopen("GTBL.dat","rb+");if(fp == NULL){printf("错误:不能打开 GTBL.dat\n");system("pause");looperror:printf("\n请输入你要打开的文件名\n");scanf("%s",temp_name);printf("读取成功\n");}while(1){pEnd = (Road *)malloc(sizeof(Road));fread( temp_data_size,sizeof(unsigned short),1,fp );pCur->stRoadRec.data_size = M_CHG_INT16(temp_data_size[0]);//printf("%d",pCur->stRoadRec.data_size);fread( temp_LinkID,sizeof(unsigned int),1,fp ););pCur->stRoadRec.roadnameflag = ( (0x80 & temp_info[0])>>7 );if(pCur->stRoadRec.roadnameflag == 1){pCur->stRoadRec.roadname=(char*)malloc(pCur->stRoadRec.data_size-12);//pri ntf("%d",pCur->stRoadRec.data_size-12);p_name = (char*)malloc(pCur->stRoadRec.data_size-12);fread(pCur->stRoadRec.roadname,(pCur->stRoadRec.data_size-12),1,fp);//pCur->stRoadRec.roadname = p_name;}pCur=pCur->next;}pCur->next=NULL;return head;}void QListSort(Road **head, Road *end){Road *right;right_walk = &right;left_count = right_count = 0;//取第一个节点作为比较的基准,小于基准的在左面的子链表中, //大于基准的在右边的子链表中for (old = (*head)->next; old != end; old = old->next){if (old->stRoadRec.LinkID < pivot->stRoadRec.LinkID) //小于基准,加入到左面的子链表,继续比较{*right_walk = old;right_walk = &(old->next);}}//合并链表*right_walk = end; //结束右链表*left_walk = pivot; //把基准置于正确的位置上 pivot->next = right; //把链表合并QListSort(head, pivot);head = &(pivot->next);count = right_count;}}while (count > 1);}Road * BubbleSort(Road *head){for (endpt=NULL; endpt!=head; endpt=p) /*结合第6点理解*/ {for (p=p1=head; p1->next->next!=endpt; p1=p1->next) {if (p1->next->stRoadRec.LinkID> p1->next->next->stRoadRec.LinkID) /*如果前面的节点键值比后面节点的键值大,则交换*/{p2 = p1->next->next; /*结合第1点理解*/p1->next->next = p2->next; /*结合第2点理解*/free(p1); /*释放p1*/p1 = NULL; /*p1置为NULL,保证不产生“野指针”,即地址不确定的指针变量*/return head;}Road *SelectSort(Road *head){Road *first; /*排列后有序链的表头指针*/Road *tail; /*排列后有序链的表尾指针*/{if (p->next->stRoadRec.LinkID < min->stRoadRec.LinkID) /*找到一个比当前min小的节点。