创建链表
#include<iostream>
using namespace std;
struct ListNode{
int val;
ListNode *next;
ListNode():val(0),next(nullptr){};
ListNode(int val):val(val),next(nullptr){};
ListNode(int val,ListNode *ptr):val(val),next(ptr){};
};
int main(){
//输入链表
int temp;
cin>>temp;
ListNode *head=new ListNode(temp);
ListNode *ptr=head;
while(cin.peek()!='\n'){
cin>>temp;
ptr->next=new ListNode(temp);
ptr=ptr->next;
}
ptr->next=nullptr;
while(head){
cout<<head->val<<" ";
head=head->next;
}
return 0;
}