Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1589258
  • 博文数量: 354
  • 博客积分: 8137
  • 博客等级: 中将
  • 技术积分: 5137
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-26 15:40
文章分类

全部博文(354)

文章存档

2010年(300)

2009年(54)

分类: C/C++

2010-07-07 06:55:31

#include <stdio.h>
#include <stdlib.h>

struct chain
{
    int value;
    struct chain *next;

};

struct chain *create()
{
    struct chain *head, *tail, *p;
    int x;
    head = tail = NULL;
    printf("Input data.\n");
    while(scanf("%d", &x) == 1)
    {
        p = (struct chain *)malloc (sizeof(struct chain));
        p->value = x;
        p->next = NULL;
        if(head == NULL)
            head = tail = p;
        else
            tail = tail ->next;
        tail ->next = p;

    }
    return head;
};

int main(int argc, char *argv[])
{
    struct chain *p, *q;
    q = create();
    while(q)
    {
        printf("%d\n", q->value);
        p = q->next;
        free(q);
        q = p;
    }
    system("pause");
    return 0;
}


阅读(680) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~