ListNode.cpp

//顶级垃圾程序
//A very bad program
#include <bits/stdc++.h>
using namespace std;

vector<int> vec;
struct ListNode{
	int val;
	ListNode *next;
	ListNode() : val(INT_MIN), next(nullptr){}
	ListNode(int _val) : val(_val), next(nullptr){}
};
ListNode *buildList(vector<int> &nums) {
    ListNode *head = new ListNode();
    ListNode *cur = head;
    for (int i = 0; i < int(nums.size()); i++) {
        cur->next = new ListNode(nums[i]);
        cur = cur->next;
    }
    return head->next;
}
void OutPutList(ListNode *head){
	ListNode *cur = head;
	while(cur){
//		vec.push_back(cur->val);
		cout << cur->val << " ";
		cur = cur->next;
	}
}
int main(){
	int num;
	vector<int> nums;
	while (cin >> num){
		nums.push_back(num);
		if (cin.get() == '\n') break;
	}
	ListNode *cur = buildList(nums);
	OutPutList(cur);
	return 0;
}

image image