skip to content
developertype

snippets

filter:96 snippets
cpp-gen-uniqueptr·cpp·general
#include <memory>

struct Node {
    int val;
    std::unique_ptr<Node> next;
    Node(int v) : val(v), next(nullptr) {}
};

std::unique_ptr<Node> makeList(int n) {
    auto head = std::make_unique<Node>(0);
    Node* cur = head.get();
    for (int i = 1; i < n; ++i) {
        cur->next = std::make_unique<Node>(i);
        cur = cur->next.get();
    }
    return head;
}