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

    数据结构实验之链表二:逆序建立链表

    TimeLimit: 1000MS Memory limit: 65536K

    题目描述

    输入整数个数N,再输入N个整数,按照这些整数输入的相反顺序建立单链表,并依次遍历输出单链表的数据。

    输入

    第一行输入整数N;

    第二行依次输入N个整数,逆序建立单链表。

    输出

    依次输出单链表所存放的数据。

    示例输入

    10

    113 5 27 9 12 43 16 84 22

    示例输出

    2284 16 43 12 9 27 5 3 11

    #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;
        for(int i=1; i<=n; i++)
        {
            p=new node;
            p->next=head->next;
            cin>>p->data;
            head->next=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;
        cin>>n;
        Creat();
        Output();
        return 0;
    }


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

  • 相关阅读:
    NOI 题库 7084
    NOI 题库 7218
    POJ 2386 题解
    NOI 题库 8465
    NOI 题库 2753
    NOI 题库 1792
    P3709 大爷的字符串题
    初探莫队
    P1026 统计单词题解
    AC自动机小记
  • 原文地址:https://www.cnblogs.com/juechen/p/4722064.html
Copyright © 2011-2022 走看看