题解 | #牛牛的单向链表#
牛牛的单向链表
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;
}