- 最後登錄
- 2024-8-13
- 在線時間
- 86 小時
- 註冊時間
- 2007-7-17
- 閱讀權限
- 20
- 精華
- 0
- UID
- 1842453
- 帖子
- 172
- 積分
- 144 點
- 潛水值
- 33808 米
| 本帖最後由 滄浪水 於 2012-4-8 11:48 PM 編輯
最主要是
a->next = b; b->next = c; 這兩行你都寫成 == 了
另外遍歷 linked list 的方法也有問題
while 這裡幫你改一下
從你程式寫的方式 linked list 概念你可還不是很清楚
可以的話再翻翻書吧- int main ()
- {
- struct circle {
- int x, y;
- int index;
- int radius;
- struct circle *next;
- };
- struct circle *a, *b, *c, *current;
- a = (struct circle *)malloc(sizeof(struct circle));
- a->index = 1;
- print f("請輸入第一個圓的圓心(x, y): ");
- scanf("%d %d", &a->x, &a->y);
- print f("請輸入第一個圓的半徑: ");
- scanf("%d", &a->radius);
- a->next = NULL;
- b = (struct circle *)malloc(sizeof(struct circle));
- b->index = 2;
- print f("請輸入第二個圓的圓心(x, y): ");
- scanf("%d %d", &b->x, &b->y);
- print f("請輸入第二個圓的半徑: ");
- scanf("%d", &b->radius);
- b->next = NULL;
- a->next = b;
- c = (struct circle *)malloc(sizeof(struct circle));
- c->index = 3;
- print f("請輸入第三個圓的圓心(x, y): ");
- scanf("%d %d", &c->x, &c->y);
- print f("請輸入第三個圓的半徑: ");
- scanf("%d", &c->radius);
- c->next = NULL;
- b->next = c;
- current = a;
- do
- {
- print f("第%d個圓的圓心為(%d, %d), 半徑為%d\n",
- current->index, current->x, current->y, current->radius);
- current = current->next;
- }while (current != NULL);
- free(a);
- free(b);
- free(c);
- system("PAUSE");
- return 0;
- }
複製代碼 ... |
|