當前位置:首頁 » 存儲配置 » 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-08-14 17:06:30 瀏覽:958
我的世界嗨皮伺服器怎麼關服了 發布:2025-08-14 16:48:55 瀏覽:418
怎麼可以修改手機配置 發布:2025-08-14 16:44:09 瀏覽:310
php網頁地址 發布:2025-08-14 16:37:57 瀏覽:558
安卓手機有什麼資源 發布:2025-08-14 16:29:19 瀏覽:407
數列極限的四則運演算法則 發布:2025-08-14 16:28:23 瀏覽:965
互聯網文件夾 發布:2025-08-14 15:55:21 瀏覽:697
python編譯為dll 發布:2025-08-14 15:43:40 瀏覽:792
機變酷卡編程 發布:2025-08-14 15:25:54 瀏覽:884
ftp亂碼上傳 發布:2025-08-14 15:25:52 瀏覽:732