#include "stdio.h"#include "stdlib.h"#include "string.h"typedef struct Node{ char name[10]; int x,y; struct Node *next;}Node,*Linklist;void main(){ void checkname(Node *L); void checklocation(Node *L); struct Node *L,*temp; char nametemp[10]; int xtmp=0,ytmp=0; int flag=1,check; L=(Linklist)malloc(sizeof(Node)); (*L).next=NULL; temp=(Linklist)malloc(sizeof(Node)); (*temp).next=NULL; while(flag) { printf("Please input the cities' name: "); scanf("%s",&nametemp); printf("Please input the location: "); scanf("%d%d",&xtmp,&ytmp); if(xtmp!=0&&strlen(nametemp)<10) { temp=(Node*)malloc(sizeof(Node)); strcpy(temp->name,nametemp); temp->x=xtmp; temp->y=ytmp; temp->next=L->next; L->next=temp; } else flag=0; } printf("Please select the service. 1.Find location by name. 2.Find name by location."); scanf("%d",&check); switch(check) { case 1: checkname(L); }}////////////////////////////////////由名字找位置//////////////////////////////////void checkname(Node *L){ char sname[10]; printf("Please input the name: "); scanf("%s",&sname); printf("Name:%s. Location:%d %d",&sname,&(*L).x,&(*L).y); while(L!=NULL) { L=L->next; }}

评论