回覆列表
  • 1 # 使用者5274464177346

    #include <stdio.h>#include <string.h>struct stu {int data;struct stu *next;};#define LEN sizeof(struct stu)void create(struct stu **head){struct stu *p1,*p2;int n = 0;p1 = p2 = (struct stu *)malloc(LEN);scanf("%d",&p2->data);*head = p1;while(n<10){p1->next = p2;p2 = (struct stu *)malloc(LEN);scanf("%d",&p2->data);n++;}p1->next = NULL;return;}void main(void){struct stu *head;create(&head);}

  • 2 # pietr49411

    假設你的連結串列的節點定義為struct node{ int data; ///當然,其他型別也可以 struct node* next;}*head;建立空連結串列可以用下面語句head=(struct node*)malloc(sizeof(struct node));head->next=NULL;這是一種,但是有時候我們設計的連結串列可能不需要一個單獨的節點,那麼就直接使用head=NULL就可以表示空連結串列了。

  • 中秋節和大豐收的關聯?
  • 兩相電機接好正反開關以後轉速達不到怎麼回事?