---
# System prepended metadata

title: Insert value to linked list

---

# Insert value to linked list

```cpp=
struct ListNode {
    int val;
    struct ListNode* next;
}

struct ListNode* creat_linked_list(vector<int> &vec) {

    struct ListNode *head = new ListNode;
    struct ListNode *current;

    head->val = vec[0];
    head->next = NULL;
    current = head;

    for(int i = 1; i < vec.size(); i++) {
        struct ListNode *node = new ListNode;
        node->val = vec[i];
        node->next = NULL;
        current->next = node;
        current = current->next;
    }

    return head;
}
```