/
githubmirror
/
hello-algo
Обзор
Документация
Войти
/
githubmirror
/
hello-algo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
en/codes/cpp/utils/list_node.hpp
42 строки
805 B
Yudong Jin
Translate all code to English (#1836)
31 дек 2025, 02:44
Не верифицирован
31 дек 2025, 02:44
2778a6f
Код
Авторство
О чём код?
/** * File: list_node.hpp * Created Time: 2021-12-19 * Author: krahets (krahets@163.com) */ #pragma once #include <iostream> #include <vector> using namespace std; /* Linked list node */ struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(nullptr) { } }; /* Deserialize a list into a linked list */ ListNode *vecToLinkedList(vector<int> list) { ListNode *dum = new ListNode(0); ListNode *head = dum; for (int val : list) { head->next = new ListNode(val); head = head->next; } return dum->next; } /* Free memory allocated to linked list */ void freeMemoryLinkedList(ListNode *cur) { // Free memory ListNode *pre; while (cur != nullptr) { pre = cur; cur = cur->next; delete pre; } }