本题要求实现一个函数按照输入数据的顺序建立一个链表。函数接口定义:struct ListNode createlist;函数createlist利用scanf从输入中获取一系列正整数当读到−1时表示输入结束。按输入数据的逆序建立一个链表并返回链表头指针。链表节点结构定义如下:struct ListNode int data; struct ListNode next;;裁判测试程序样
struct ListNode *createlist() { int num; struct ListNode *head = NULL, p; scanf("%d", &num); while (num != -1) { p = (struct ListNode)malloc(sizeof(struct ListNode)); p->data = num; p->next = head; head = p; scanf("%d", &num); } return head; }
原文地址: https://www.cveoy.top/t/topic/cFFR 著作权归作者所有。请勿转载和采集!