题解 | #牛牛的单向链表#

牛牛的单向链表

http://www.nowcoder.com/practice/95559da7e19c4241b6fa52d997a008c4

#include <bits/stdc++.h>
using namespace std;
struct Node
{
    int val;
    Node *next;
    Node():val(0),next(NULL){}
};
int main()
{
    int n,x;
    cin>>n;
    Node *head=new Node();
    auto q=head;
    while(n--){
        cin>>x;
        q->next=new Node();
        q->next->val=x;
        q=q->next;
    }
    q=head->next;
    while(q){
        cout<<q->val<<" ";
        q=q->next;
    }
    return 0;
}
全部评论

相关推荐

醉蟀:你不干有的是人干
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务