Publish the C codes to the docs. (#469)

This commit is contained in:
Yudong Jin
2023-04-18 20:21:31 +08:00
committed by GitHub
parent 6723cdbc7e
commit dbc4906582
29 changed files with 288 additions and 189 deletions
@@ -42,6 +42,7 @@ void insert(int *nums, int size, int num, int index) {
}
/* 删除索引 index 处元素 */
// 注意:stdio.h 占用了 remove 关键词
void removeItem(int *nums, int size, int index) {
// 把索引 index 之后的所有元素向前移动一位
for (int i = index; i < size - 1; i++) {
@@ -14,8 +14,7 @@ void insert(ListNode *n0, ListNode *P) {
}
/* 删除链表的节点 n0 之后的首个节点 */
// 由于引入了 stdio.h ,此处无法使用 remove 关键词
// 详见 https://github.com/krahets/hello-algo/pull/244#discussion_r1067863888
// 注意:stdio.h 占用了 remove 关键词
void removeNode(ListNode *n0) {
if (!n0->next)
return;
@@ -6,7 +6,7 @@
#include "../include/include.h"
// 用数组实现 list
/* 列表类简易实现 */
struct myList {
int *nums; // 数组(存储列表元素)
int capacity; // 列表容量
@@ -16,10 +16,9 @@ struct myList {
typedef struct myList myList;
/* 前置声明 */
void extendCapacity(myList *list);
/* 构造方法 */
/* 构造函数 */
myList *newMyList() {
myList *list = malloc(sizeof(myList));
list->capacity = 10;
@@ -29,7 +28,7 @@ myList *newMyList() {
return list;
}
/* 析构方法 */
/* 析构函数 */
void delMyList(myList *list) {
free(list->nums);
free(list);
@@ -77,8 +76,7 @@ void insert(myList *list, int index, int num) {
}
/* 删除元素 */
// 由于引入了 stdio.h ,此处无法使用 remove 关键词
// 详见 https://github.com/krahets/hello-algo/pull/244#discussion_r1067863888
// 注意:stdio.h 占用了 remove 关键词
int removeNum(myList *list, int index) {
assert(index >= 0 && index < size(list));
int num = list->nums[index];