- #include <stdlib.h>
- #include <stdio.h>
- typedef struct _node{
- int value;
- struct _node *next;
- }Node;
- typedef struct list{
- Node *head;
- Node *tail;
- }List;
- int main(){
- int number;
- List list;
- list.head = list.tail = NULL;
-
- do{
- scanf("%d", &number);
- //接收一个Number
- if (number != -1){
- Node *p = (Node *)malloc(sizeof(Node));
- p->value = number;
- p->next = NULL;
- //如果头存在
- if (list.tail){
- list.tail->next = p;
- list.tail = p;
- }else{
- list.head = list.tail = p;
- }
- }
- }while (number != -1);
- Node *p = list.head;
- do{
- printf("%d\t", p->value);
- p = p->next;
- }while(p);
- return 0;
- }
复制代码
很适合有顺序的一组数据搜索之类的功能,都可以套用 |
|