c数据结构 -- 使用链表实现计数
#include <stdio.h> #include <stdlib.h> typedef struct _node{ int value; struct _node *next; } Node; int main(void) { Node * head = NULL; int num,i; i =0; do{ scanf("%d",&num); if(num != -1){ Node *p = (Node*)malloc(sizeof(Node)); p->value = num; p->next = NULL; // find the last if(i != 0){ Node *last = head; while(last->next){ last = last->next; } last->next = p; }else{ head = p; } i++; } }while(num != -1); do{ printf("数字:%d",head->value); head = head->next; }while(head); return 0; }