zoukankan      html  css  js  c++  java
  • 顺序建立链表 分类: 链表 2015-06-07 12:43 15人阅读 评论(0) 收藏

    数据结构实验之链表一:顺序建立链表

    TimeLimit: 1000MS Memory limit: 65536K

    题目描述

    输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据。

    输入

    第一行输入整数的个数N

    第二行依次输入每个整数。

    输出

    输出这组整数。

    示例输入


    8

    1256 4 6 55 15 33 62

    示例输出

    1256 4 6 55 15 33 62

    #include <bits/stdc++.h>
    #define WW freopen("input.txt","r",stdin)
    #define RR freopen("ouput.txt","w",stdout)
    using namespace std;
    struct node
    {
        int data;
        node *next;
    }*head;
    int n;
    void Creat()
    {
        node *p,*tail;
        tail=head;
        for(int i=1; i<=n; i++)
        {
            p=new node;
            p->next=NULL;
            cin>>p->data;
            tail->next=p;
            tail=p;
        }
    }
    
    void Output()
    {
        node *p;
        p=head->next;
        while(p)
        {
            if(p!=head->next)
                cout<<" ";
            cout<<p->data;
            p=p->next;//这里不要忘记
        }
        cout<<endl;
    }
    int main()
    {
        head=new node;
        head->next=NULL;
    //    WW;
    //    RR;
        cin>>n;
        Creat();
        Output();
        return 0;
    }


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Javascript函数节流 (转)
    XMLHttpRequest get post
    ast基础学习
    python xpath xml namespaces|How does XPath deal with XML namespaces?
    aiohttp
    asyncio异步
    sql server 查看版本
    毕设设计进度03
    bzoj 2453: 维护队列
    bzoj 3262: 陌上花开
  • 原文地址:https://www.cnblogs.com/juechen/p/4722065.html
Copyright © 2011-2022 走看看