当前位置:文档之家› 电子地图管理系统

电子地图管理系统

电子地图管理系统-标准化文件发布号:(9456-EUATWK-MWUB-WUNN-INNUL-DDQTY-KII#include <cstdio>#include <cstdlib>#include <malloc.h>#include <cstring>#include <ctime>#include <string>#include <algorithm>#include <iostream>using namespace std;void start();void display();void displaypaixu();void displayjiansuo();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");scanf("%d",&Class);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("无数据源");system("pause");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);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;p = p->next;i++;}temp_head=temp_head->next;}end->next=NULL;p ->next = NULL;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);}void SearchById(Road *head){time_t a,b;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));temp_head = head;if(temp_head == NULL){printf("无数据源");system("pause");exit(3);}while(temp_head!=NULL){if(temp_head->stRoadRec.LinkID==LinkId){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;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++;}temp_head=temp_head->next;}p ->next = NULL;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);}void SearchByName(Road *head){time_t a,b;Road *prev,*p,*end,*temp_head;char Run_time[80];int i=0;char Name[30];printf("请输入您所要查找的道路的名称:\n");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("无数据源");system("pause");exit(6);}while(temp_head!=NULL){if(strcmp(temp_head->stRoadRec.roadname,Name)==0){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;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++;}temp_head=temp_head->next;}p ->next = NULL;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);}void updata(Road*head){FILE*pp;FILE*ppp;FILE*infile;FILE*outfile;time_t a;char filename[20];Road*p1;Road*p2;pp=fopen("newfile.txt","w");if(pp==NULL){printf("文件创建失败\n");exit(1);}//判断文件是否创建成功//p1=head;if(p1==NULL){printf("空指针\n");}//判断头指针是否为空//while(p1!=NULL){fprintf(pp,"%d%d%d%s%d%d",p1->stRoadRec.data_size,p1->stRoadRec.LinkID,p1->stRoadRec.road_size,p1->stRoadRec.roadname,p1->stRoadRec.brunch,p1->stRoadRec.linkid);p1=p1->next;}fclose(pp);//将动态链表中的内容写入文件newfile中//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);//将文件中的内容读出来作为文件名//fclose(outfile);//将时间加入到文件名中,使更新后之前的文件内容不会被覆盖//ppp=fopen(filename,"wb");if(ppp==NULL)printf("更新文件创建失败\n");p2=head;while(p2!=NULL){fwrite(p2,sizeof(Road),1,ppp);p2=p2->next;}printf("文件更新中...\n");printf("文件更新成功\n");fclose(ppp);//文件更新完毕,将排序后的内容写入文本文件和二进制文件中//}void SearchByBruch(Road *head){time_t a,b;Road *prev,*p,*end,*temp_head;char Run_time[80];int i=0,Bruch;printf("请输入您所要查找的道路的岔路数:\n");scanf("%d",&Bruch);p=(Road *)malloc(sizeof(Road));//创建一个结点prev=p;a=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&a));temp_head = head;if(temp_head == NULL){printf("无数据源");system("pause");exit(4);}while(temp_head!=NULL){if(temp_head->stRoadRec.brunch==Bruch){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;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++;}temp_head = temp_head->next;}p->next = NULL;if(i>=5){printf("i的结果是%d\n",i);save(prev);printf("查询结果数大于5,已保存至SearchResult.txt\n");}b=time(NULL);strftime(Run_time,79,"%H:%M:%S",localtime(&b));printf("本次查找用时%d 秒.\n",b-a);}Road* readfile(void){FILE *fp;unsigned short temp_data_size[1]; //数据大小 2byte buff unsigned int temp_LinkID[1]; //道路编号 4byte buffunsigned short temp_road_size[1]; //道路名称的尺寸 2byte buff unsigned int temp_info[1]; //道路信息 4byte buffchar temp_name[5000]; //GTBL.dat 不存在就输入char *p_name; //道路名称指针Road *head,*pCur,*pEnd;pCur = (Road *)malloc(sizeof(Road));head=pCur;fp = fopen("GTBL.dat","rb+");if(fp == NULL){printf("错误:不能打开 GTBL.dat\n");system("pause");looperror:printf("\n请输入你要打开的文件名\n");scanf("%s",temp_name);fp = fopen( temp_name,"rb+");if( fp == NULL){printf("错误:不能打开%s",temp_name);goto looperror;}}else{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.LinkID = M_CHG_INT32(temp_LinkID[0]);fread( temp_road_size,sizeof(short),1,fp );pCur->stRoadRec.road_size = M_CHG_INT16(temp_road_size[0]);fread( temp_info,sizeof(unsigned int),1,fp );temp_info[0] = M_CHG_INT32( temp_info[0] );pCur->stRoadRec.linkid = ( 0xf & temp_info[0] ); //printf("%d",pCur->stRoadRec.linkid);pCur->stRoadRec.brunch = ( (0x70 & temp_info[0])>>4 );pCur->stRoadRec.roadnameflag = ( (0x80 & temp_info[0])>>7 );if(pCur->stRoadRec.roadnameflag == 1){pCur->stRoadRec.roadname=(char*)malloc(pCur->stRoadRec.data_size-12);//printf("%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;}else{pCur->stRoadRec.roadname = NULL;}if(feof(fp)){break;}pCur->next = pEnd;pCur=pCur->next;}pCur->next=NULL;return head;}void QListSort(Road **head, Road *end){Road *right;Road **left_walk, **right_walk;Road *pivot, *old;int count, left_count, right_count;if (*head == end)return;do{pivot = *head;left_walk = head;right_walk = &right;left_count = right_count = 0;//取第一个节点作为比较的基准,小于基准的在左面的子链表中,//大于基准的在右边的子链表中for (old = (*head)->next; old != end; old = old->next){if (old->stRoadRec.LinkID < pivot->stRoadRec.LinkID) //小于基准,加入到左面的子链表,继续比较{++left_count;*left_walk = old; //把该节点加入到左边的链表中,left_walk = &(old->next);}else //大于基准,加入到右边的子链表,继续比较{++right_count;*right_walk = old;right_walk = &(old->next);}}//合并链表*right_walk = end; //结束右链表*left_walk = pivot; //把基准置于正确的位置上pivot->next = right; //把链表合并//对较小的子链表进行快排序,较大的子链表进行迭代排序。

相关主题