当前位置:首页 » 存储配置 » c存储坐标

c存储坐标

发布时间: 2024-09-05 03:01:36

⑴ 设计一个散列函数,用它存储二维点的坐标。这是我们的c语言编程作业,我写了如下代码,但是有BUG:

这个已经帮你改了,你可以运行一下
# include <stdio.h>
# include <malloc.h>
# include <string.h>
#define NHASH 31

typedef struct zuobiao
{
int x;
int y;
struct zuobiao * next; //chain
}Nameval;

//函数声明
Nameval * create();

Nameval *srt(Nameval *head,Nameval *t);

void main(void)
{

Nameval * sym,*head;
head=create();
//print(head);
sym=(struct zuobiao*)malloc(sizeof(struct zuobiao));
printf("请输入要查找的坐标值:\nx = ");
scanf("%d", &sym->x);
printf("y = "); scanf("%d", &sym->y);
srt(head,sym);

}
///////////////////////////////////////////////////////////////
Nameval * create()
{
Nameval *head,*tail,*p;int x;
head= tail=NULL;
printf("请输入坐标点的个数:");
scanf("%d",&x);
while(x>0)
{
p=(struct zuobiao*)malloc(sizeof(struct zuobiao));
printf("请输入坐标的值:\nx = ");
scanf("%d", &p->x);
printf("y = "); scanf("%d", &p->y);

//p->age=x;
p->next=NULL;
if(head==NULL)
{
head=tail=p;
}
else
{
tail->next=p;
tail=p;
}
x--;
}

return(head);
}

//////////////////////////////////////////////////////////////////

Nameval *srt(Nameval *head,Nameval *t)
{
Nameval *p,*q;
p=(Nameval *)malloc(sizeof(Nameval));
p=head;
if(p==NULL) return NULL;
while(((p->x!=t->x)||(p->y!=t->y))&&(p->next!=NULL))
{
q=p;
p=p->next;
}
if((p->x==t->x)&&(p->y==t->y))
{
printf("已经有了这个坐标\n");
}
else if((p->next==NULL)&&(p->x!=t->x))
{

p->next=t;
t->next=NULL;
printf("新坐标已经插入\n");

}
//free(p);
return head;
}
可以推荐你加QQ群218691837

⑵ c语言中若要输入坐标应该怎么办

先算出纵坐标的值,然后
用二维数组来存储坐标,如:int a[5][5]; 可以用a[0][0] a[0][1]....
a[i][j]....a[4][3] a[4][4],来存储5对坐标值,i、j分别是横坐标和纵坐标。

热点内容
电脑服务器电源好还是普通电源好 发布:2025-05-17 22:53:53 浏览:19
消防防诈骗脚本 发布:2025-05-17 22:49:31 浏览:876
凯酷2021选哪个配置 发布:2025-05-17 22:46:06 浏览:659
苹果好用的解压软件 发布:2025-05-17 22:42:23 浏览:381
我的世界服务器莫名崩溃 发布:2025-05-17 22:40:57 浏览:477
我的世界utc服务器ip 发布:2025-05-17 22:36:19 浏览:740
新闻压缩要素 发布:2025-05-17 22:22:11 浏览:118
耳机没有声音怎么办安卓 发布:2025-05-17 22:16:29 浏览:583
bc8android导航 发布:2025-05-17 22:15:50 浏览:639
什么配置的车标好 发布:2025-05-17 21:41:20 浏览:203