救命!!数据结构课程设计——城市链表,紧急啊!2011/1/10号之前交

sigu199011 2011-01-02 12:21:35
城市链表
[问题描述]
将若干城市的信息,存入一个带头结点的单链表。结点中的城市信息包括:城市名,城市的位置坐标。要求能够利用城市名和位置坐标进行有关查找、插入、删除、更新等操作。
[基本要求]
(1) 给定一个城市名,返回其位置坐标;
(2) 给定一个位置坐标P和一个距离D,返回所有与P的距离小于等于D的城市。
[测试数据]
由学生依据软件工程的测试技术自己确定。注意测试边界数据。
希望各位高手相救!小女不胜感激,临表涕零,数据结构是C语言版的。有曾经做过的请帮帮忙谢谢各位!!
网上的代码有错,希望原创的,老师还说最好有VC++6.0的图像用户界面,不要像菜单一样的界面。
...全文
473 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
JiangXiang 2011-01-03
  • 打赏
  • 举报
回复
原来你想要编windows程序,那还是赶紧学MFC吧
sigu199011 2011-01-03
  • 打赏
  • 举报
回复
还有谁知道怎样图形用户界面GUI,在VC++6.0中,我希望城市链表是对话框的形式。
sigu199011 2011-01-03
  • 打赏
  • 举报
回复
算了,时间太紧了,就用菜单形式吧,谢谢各位,尤其是2楼的高手,谢谢!
sigu199011 2011-01-02
  • 打赏
  • 举报
回复
1楼的怎么不写全啊??2楼的很谢谢您的苦心,可是对我来说很有难度啊。
chaoliu1024 2011-01-02
  • 打赏
  • 举报
回复
给你一个通讯录的程序,你要做些改动,把一些变量名换成城市差不多就可以了
/* A simple mailing list program that illustrates the use and maintence  
of doubly linked lists. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct address{
char name[30];
char street[40];
char city[20];
char state[3];
char zip[11];

struct address *next; /* pointer to next entry */
struct address *prior; /* pointer to previous record */
};

struct address *start; /* pointer to first entry in list */
struct address *last; /* pointer to last entry */
struct address *find(char*);

void enter(void),search(void),save(void);
void load(void),list(void);
void mldelete(struct address **,struct address **);
void dls_store(struct address *i,struct address **start,struct address **last);
void inputs(char *,char *,int);
void display(struct address *);
int menu_select (void);

int main(void)
{
start = last = NULL; /* initialize start and end pointers */

for(;;){
switch(menu_select()){
case 1: enter (); /* enter an address */
break;
case 2: mldelete(&start,&last); /* remove an address */
break;
case 3: list(); /* display the list */
break;
case 4: search(); /* find an address */
break;
case 5: save(); /* save list to disk */
break;
case 6: load(); /* read from disk */
break;
case 7: exit(0);
}
}
return 0;
}

/* Select an operation. */
int menu_select(void)
{
char s[80];
int c;

printf("1.Entry a name \n");
printf("2.Delete a name \n");
printf("3.List the file \n");
printf("4.Search \n");
printf("5.Save the file \n");
printf("6.Load the file \n");
printf("7.Quit \n");
do {
printf("\n Enter your choice:");
gets(s);
c = atoi(s);
}while(c<0||c>7);
return c;
}

/* Enter names and address. */
void enter(void)
{
struct address *info;

for(;;){
info= (struct address *)malloc(sizeof(struct address));
if(!info){
printf("\n out of memory");
return;
}

inputs("Enter name:", info->name,30);
if(!info->name[0]) break; /* stop entering */
inputs("Enter street:",info->street,40);
inputs("Enter city:",info->city,20);
inputs("Enter state:",info->state,3);
inputs("Enter zip:",info->zip,10);

dls_store(info,&start,&last);
} /* entry loop */
}

/* This function will input a string up to the length in count and will
prevent the string from being overrun . It will also display a prompting message. */
void inputs(char *prompt,char *s,int count)
{
char p[255];

do {
printf(prompt);
fgets(p,254,stdin);
if(strlen(p) > (unsigned int)count) printf("\n Too Long \n");
}while(strlen(p) > (unsigned int)count);

p[strlen(p)-1] = 0; // remove newline charater
strcpy(s,p);
}


/* Create a doubly linked list in sorted order. */
void dls_store(
struct address *i, /* new element */
struct address **start, /* firsr element in list */
struct address **last /* last element in list */
)
{
struct address *old,*p;

if(*last == NULL){ /* first element in list */
i->next = NULL;
i->prior = NULL;
*last = i;
*start = i;
return;
}
p = *start; /* start at top list */

old = NULL;
while (p){
if (strcmp(p->name,i->name)<0){
old = p;
p = p->next;
}
else {
if(p->prior){
p->prior->next = i;
i->next = p;
i->prior = p->prior;
p->prior = i;
return;
}
i->next = p; /* new first element */
i->prior = NULL;
p->prior = i;
*start = i;
return ;
}
}
old->next = i; /* put on old */
i->next = NULL;
i->prior = old;
*last = i;
}

/* Remove an element from the list. */
void mldelete(struct address **start,struct address **last)
{
struct address *info;
char s[80];

inputs("Enter name:",s,30);
info = find(s);
if(info){
if(*start == info){
*start = info->next;
if(*start)((*start)->prior) = NULL;
else *last = NULL;
}
else{
info->prior->next = info->next;
if(info!=*last)
info->next->prior = info->prior;
else
*last = info->prior;
}
free(info); /* return memory to system */
}
}

/* Find an address. */
struct address *find(char *name)
{
struct address *info;

info = start;
while (info){
if(!strcmp(name,info->name))return info;
info = info->next; /* get next address */
}
printf("Name not found. \n");
return NULL; /* not found */
}

/* Display the entire list. */
void list(void)
{
struct address *info;

info = start;
while(info){
display(info);
info = info->next; /* get next address */
}
printf("\n \n");
}

/* This function actually prints the fields in each address. */
void display(struct address *info)
{
printf("%s \n",info->name);
printf("%s \n",info->street);
printf("%s \n",info->city);
printf("%s \n",info->state);
printf("%s \n",info->zip);
printf("\n \n");
}

/* Look for a name in the list. */
void search(void)
{
char name[40];
struct address *info;

printf("Enter name to find:");
gets(name);
info = find(name);
if (!info)printf("Not Found \n");
else display(info);
}

/* Save the file to disk */
void save(void)
{
struct address *info;

FILE *fp;

fp = fopen("mlist.txt","wb");
if(!fp){
printf("Cannot open file. \n");
exit(1);
}
printf("\n Saving File \n");

info = start;
while(info){
fwrite(info,sizeof(struct address),1,fp);
info = info->next; /* get next address */
}
fclose(fp);
}

/* Load the address file. */
void load()
{
struct address *info;

FILE *fp;

fp = fopen("mlist.txt","rb");
if(!fp){
printf("Cannot open file.\n");
exit(1);
}

/* free any previously allocated memory */
while (start){
info = start->next;
free(info);
start = info;
}

/* reset top bottom pointers */
start = last = NULL;

printf("\n Loading File \n");
while(!feof(fp)){
info = (struct address *)malloc(sizeof(struct address));
if(!info){
printf("Out of Memory");
return;
}
if(1 != fread(info,sizeof(struct address),1,fp))break;
dls_store(info,&start,&last);
}
fclose(fp);
}
kusey 2011-01-02
  • 打赏
  • 举报
回复

typedef struct _coordinate {
double _x;
double _y;
} Coordinate;

typedef struct _city_information {
char _name[64];
Coordinate _coor;
} CityInfo;

typedef struct _node {
CityInfo _info;
struct _node *_next;
} Node;

typedef struct _list {
Node *_nodes;
int _count;
} List;

int list_create( List **pList );
int list_insert( List *pList, const CityInfo ci );
int list_remove( List *pList, const char *name );

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧