电子地图管理系统.docx
- 文档编号:12378000
- 上传时间:2023-06-05
- 格式:DOCX
- 页数:26
- 大小:493.06KB
电子地图管理系统.docx
《电子地图管理系统.docx》由会员分享,可在线阅读,更多相关《电子地图管理系统.docx(26页珍藏版)》请在冰点文库上搜索。
电子地图管理系统
电子地图管理系统
#include
#include
#include
#include
#include
#include
#include
#include
usingnamespacestd;
voidstart();
voiddisplay();
voiddisplaypaixu();
voiddisplayjiansuo();
Road*head=NULL;
voidSearchByClass(Road*head)
{
time_ta,b;
Road*prev,*p,*end,*temp_head;
charRun_time[80];
inti=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);
}
voidSearchById(Road*head)
{
time_ta,b;
Road*prev,*p,*end,*temp_head;
charRun_time[80];
inti=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);
}
voidSearchByName(Road*head)
{
time_ta,b;
Road*prev,*p,*end,*temp_head;
charRun_time[80];
inti=0;
charName[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);
}
voidupdata(Road*head)
{
FILE*pp;
FILE*ppp;
FILE*infile;
FILE*outfile;
time_ta;
charfilename[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);//文件更新完毕,将排序后的内容写入文本文件和二进制文件中//
}
voidSearchByBruch(Road*head)
{
time_ta,b;
Road*prev,*p,*end,*temp_head;
charRun_time[80];
inti=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;
unsignedshorttemp_data_size[1];//数据大小2bytebuff
unsignedinttemp_LinkID[1];//道路编号4bytebuff
unsignedshorttemp_road_size[1];//道路名称的尺寸2bytebuff
unsignedinttemp_info[1];//道路信息4bytebuff
chartemp_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);
gotolooperror;
}
}
else
{
printf("读取成功\n");
}
while
(1)
{
pEnd=(Road*)malloc(sizeof(Road));
fread(temp_data_size,sizeof(unsignedshort),1,fp);
pCur->stRoadRec.data_size=M_CHG_INT16(temp_data_size[0]);//printf("%d",pCur->stRoadRec.data_size);
fread(temp_LinkID,sizeof(unsignedint),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(unsignedint),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;
returnhead;
}
voidQListSort(Road**head,Road*end)
{
Road*right;
Road**left_walk,**right_walk;
Road*pivot,*old;
intcount,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
{
++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;//把链表合并
//对较小的子链表进行快排序,较大的子链表进行迭代排序。
if(left_walk>right_walk)
{
QListSort(&(pivot->next),end);
end=pivot;
count=left_count;
}
else
{
QListSort(head,pivot);
head=&(pivot->next);
count=right_count;
}
}
while(count>1);
}
Road*BubbleSort(Road*head)
{
Road*endpt;/*控制循环比较*/
Road*p;/*临时指针变量*/
Road*p1;
Road*p2;
p1=(Road*)malloc(sizeof(Road));
p1->next=head;/*注意理解:
我们增加一个节点,放在第一个节点的前面,主要是
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 电子地图 管理 系统