mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-07 13:14:19 +00:00
Add ru version (#1865)
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* File: list_node.hpp
|
||||
* Created Time: 2021-12-19
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* Узел связного списка */
|
||||
struct ListNode {
|
||||
int val;
|
||||
ListNode *next;
|
||||
ListNode(int x) : val(x), next(nullptr) {
|
||||
}
|
||||
};
|
||||
|
||||
/* Десериализовать список в связный список */
|
||||
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;
|
||||
}
|
||||
|
||||
/* Освободить память, выделенную под связный список */
|
||||
void freeMemoryLinkedList(ListNode *cur) {
|
||||
// Освободить память
|
||||
ListNode *pre;
|
||||
while (cur != nullptr) {
|
||||
pre = cur;
|
||||
cur = cur->next;
|
||||
delete pre;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user