mirror of
https://github.com/krahets/hello-algo.git
synced 2025-02-02 22:43:50 +08:00
Add code source blocks to the chapter Graph.
Fix "函数" and "方法"
This commit is contained in:
parent
d37c71b928
commit
300016393b
@ -19,7 +19,7 @@ typedef struct myList myList;
|
||||
/* 前置声明 */
|
||||
void extendCapacity(myList *list);
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
myList *newMyList() {
|
||||
myList *list = malloc(sizeof(myList));
|
||||
list->capacity = 10;
|
||||
@ -29,7 +29,7 @@ myList *newMyList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
/* 析构函数 */
|
||||
/* 析构方法 */
|
||||
void delMyList(myList *list) {
|
||||
free(list->nums);
|
||||
free(list);
|
||||
|
@ -20,7 +20,7 @@ void siftDown(maxHeap *h, int i);
|
||||
|
||||
void siftUp(maxHeap *h, int i);
|
||||
|
||||
/* 构造函数,根据切片建堆 */
|
||||
/* 构造方法,根据切片建堆 */
|
||||
maxHeap *newMaxHeap(int nums[], int size) {
|
||||
// 所有元素入堆
|
||||
maxHeap *h = (maxHeap *) malloc(sizeof(maxHeap));
|
||||
|
@ -16,7 +16,7 @@ struct ArrayQueue {
|
||||
|
||||
typedef struct ArrayQueue ArrayQueue;
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
ArrayQueue *newArrayQueue(int capacity) {
|
||||
ArrayQueue *queue = (ArrayQueue *) malloc(sizeof(ArrayQueue));
|
||||
// 初始化数组
|
||||
@ -26,7 +26,7 @@ ArrayQueue *newArrayQueue(int capacity) {
|
||||
return queue;
|
||||
}
|
||||
|
||||
/* 析构函数 */
|
||||
/* 析构方法 */
|
||||
void delArrayQueue(ArrayQueue *queue) {
|
||||
free(queue->nums);
|
||||
queue->queCapacity = 0;
|
||||
|
@ -14,7 +14,7 @@ struct linkedListStack {
|
||||
|
||||
typedef struct linkedListStack linkedListStack;
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
linkedListStack *newLinkedListStack() {
|
||||
linkedListStack *s = malloc(sizeof(linkedListStack));
|
||||
s->top = NULL;
|
||||
@ -22,7 +22,7 @@ linkedListStack *newLinkedListStack() {
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 析构函数 */
|
||||
/* 析构方法 */
|
||||
void delLinkedListStack(linkedListStack *s) {
|
||||
while (s->top) {
|
||||
ListNode *n = s->top->next;
|
||||
@ -80,7 +80,7 @@ int pop(linkedListStack *s) {
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
/* 初始化栈 */
|
||||
// 构造函数
|
||||
// 构造方法
|
||||
linkedListStack *stack = newLinkedListStack();
|
||||
|
||||
/* 元素入栈 */
|
||||
@ -109,7 +109,7 @@ int main() {
|
||||
bool empty = isEmpty(stack);
|
||||
printf("栈是否为空 = %s\n", empty ? "true" : "false");
|
||||
|
||||
/* 析构函数 */
|
||||
/* 析构方法 */
|
||||
delLinkedListStack(stack);
|
||||
return 0;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ TreeNode *rotate(TreeNode *node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
TreeNode *insertHelper(TreeNode *node, int val) {
|
||||
if (node == NULL) {
|
||||
return newTreeNode(val);
|
||||
@ -151,7 +151,7 @@ TreeNode *getInOrderNext(TreeNode *node) {
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
TreeNode *removeHelper(TreeNode *node, int val) {
|
||||
TreeNode *child, *grandChild, *temp;
|
||||
if (node == NULL) {
|
||||
|
@ -15,12 +15,12 @@ private:
|
||||
int extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
public:
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
MyList() {
|
||||
nums = new int[numsCapacity];
|
||||
}
|
||||
|
||||
/* 析构函数 */
|
||||
/* 析构方法 */
|
||||
~MyList() {
|
||||
delete[] nums;
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
/* 构造函数,根据输入列表建堆 */
|
||||
/* 构造方法,根据输入列表建堆 */
|
||||
MaxHeap(vector<int> nums) {
|
||||
// 将列表元素原封不动添加进堆
|
||||
maxHeap = nums;
|
||||
|
@ -75,7 +75,7 @@ private:
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
TreeNode* insertHelper(TreeNode* node, int val) {
|
||||
if (node == nullptr) return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入结点 */
|
||||
@ -102,7 +102,7 @@ private:
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
TreeNode* removeHelper(TreeNode* node, int val) {
|
||||
if (node == nullptr) return nullptr;
|
||||
/* 1. 查找结点,并删除之 */
|
||||
@ -183,10 +183,10 @@ public:
|
||||
return cur;
|
||||
}
|
||||
|
||||
/*构造函数*/
|
||||
/*构造方法*/
|
||||
AVLTree() : root(nullptr) {}
|
||||
|
||||
/*析构函数*/
|
||||
/*析构方法*/
|
||||
~AVLTree() {
|
||||
freeMemoryTree(root);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ class MyList
|
||||
private int numsSize = 0; // 列表长度(即当前元素数量)
|
||||
private int extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
public MyList()
|
||||
{
|
||||
nums = new int[numsCapacity];
|
||||
|
@ -113,7 +113,7 @@ class AVLTree
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
private TreeNode? insertHelper(TreeNode? node, int val)
|
||||
{
|
||||
if (node == null) return new TreeNode(val);
|
||||
@ -138,7 +138,7 @@ class AVLTree
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
private TreeNode? removeHelper(TreeNode? node, int val)
|
||||
{
|
||||
if (node == null) return null;
|
||||
|
@ -11,7 +11,7 @@ class MyList {
|
||||
int _size = 0; // 列表长度(即当前元素数量)
|
||||
int _extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
MyList() {
|
||||
_nums = List.filled(_capacity, 0);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ type myList struct {
|
||||
extendRatio int
|
||||
}
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
func newMyList() *myList {
|
||||
return &myList{
|
||||
numsCapacity: 10, // 列表容量
|
||||
|
@ -15,6 +15,7 @@ type vertex struct {
|
||||
val int
|
||||
}
|
||||
|
||||
/* 构造方法 */
|
||||
func newVertex(val int) vertex {
|
||||
return vertex{
|
||||
val: val,
|
||||
@ -28,7 +29,7 @@ type graphAdjList struct {
|
||||
adjList map[vertex]map[vertex]struct{}
|
||||
}
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
func newGraphAdjList(edges [][]vertex) *graphAdjList {
|
||||
g := &graphAdjList{
|
||||
adjList: make(map[vertex]map[vertex]struct{}),
|
||||
|
@ -14,6 +14,7 @@ type graphAdjMat struct {
|
||||
adjMat [][]int
|
||||
}
|
||||
|
||||
/* 构造方法 */
|
||||
func newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {
|
||||
// 添加顶点
|
||||
n := len(vertices)
|
||||
|
@ -15,14 +15,14 @@ type maxHeap struct {
|
||||
data []any
|
||||
}
|
||||
|
||||
/* 构造函数,建立空堆 */
|
||||
/* 构造方法,建立空堆 */
|
||||
func newHeap() *maxHeap {
|
||||
return &maxHeap{
|
||||
data: make([]any, 0),
|
||||
}
|
||||
}
|
||||
|
||||
/* 构造函数,根据切片建堆 */
|
||||
/* 构造方法,根据切片建堆 */
|
||||
func newMaxHeap(nums []any) *maxHeap {
|
||||
// 将列表元素原封不动添加进堆
|
||||
h := &maxHeap{data: nums}
|
||||
|
@ -112,7 +112,7 @@ func (t *aVLTree) insert(val int) *TreeNode {
|
||||
return t.root
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
func (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {
|
||||
if node == nil {
|
||||
return NewTreeNode(val)
|
||||
@ -140,7 +140,7 @@ func (t *aVLTree) remove(val int) *TreeNode {
|
||||
return root
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
func (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {
|
||||
if node == nil {
|
||||
return nil
|
||||
|
@ -15,7 +15,7 @@ class MyList {
|
||||
private int size = 0; // 列表长度(即当前元素数量)
|
||||
private int extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
public MyList() {
|
||||
nums = new int[capacity];
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ class GraphAdjList {
|
||||
// 请注意,vertices 和 adjList 中存储的都是 Vertex 对象
|
||||
Map<Vertex, Set<Vertex>> adjList; // 邻接表(使用哈希表实现)
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
public GraphAdjList(Vertex[][] edges) {
|
||||
this.adjList = new HashMap<>();
|
||||
// 添加所有顶点和边
|
||||
|
@ -14,7 +14,7 @@ class GraphAdjMat {
|
||||
List<Integer> vertices; // 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
|
||||
List<List<Integer>> adjMat; // 邻接矩阵,行列索引对应“顶点索引”
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
public GraphAdjMat(int[] vertices, int[][] edges) {
|
||||
this.vertices = new ArrayList<>();
|
||||
this.adjMat = new ArrayList<>();
|
||||
|
@ -14,7 +14,7 @@ class MaxHeap {
|
||||
// 使用列表而非数组,这样无需考虑扩容问题
|
||||
private List<Integer> maxHeap;
|
||||
|
||||
/* 构造函数,根据输入列表建堆 */
|
||||
/* 构造方法,根据输入列表建堆 */
|
||||
public MaxHeap(List<Integer> nums) {
|
||||
// 将列表元素原封不动添加进堆
|
||||
maxHeap = new ArrayList<>(nums);
|
||||
|
@ -96,7 +96,7 @@ class AVLTree {
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
private TreeNode insertHelper(TreeNode node, int val) {
|
||||
if (node == null) return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入结点 */
|
||||
@ -119,7 +119,7 @@ class AVLTree {
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
private TreeNode removeHelper(TreeNode node, int val) {
|
||||
if (node == null) return null;
|
||||
/* 1. 查找结点,并删除之 */
|
||||
|
@ -11,7 +11,7 @@ class MyList {
|
||||
#size = 0; // 列表长度(即当前元素数量)
|
||||
#extendRatio = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
constructor() {
|
||||
this.#nums = new Array(this.#capacity);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class Vertex {
|
||||
/* 基于邻接表实现的无向图类 */
|
||||
class GraphAdjList {
|
||||
adjList;
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
constructor(edges) {
|
||||
this.adjList = new Map();
|
||||
// 添加所有顶点和边
|
||||
|
@ -10,7 +10,7 @@ const { printHeap } = require("../include/PrintUtil");
|
||||
class MaxHeap {
|
||||
#maxHeap;
|
||||
|
||||
/* 构造函数,建立空堆或根据输入列表建堆 */
|
||||
/* 构造方法,建立空堆或根据输入列表建堆 */
|
||||
constructor(nums) {
|
||||
// 将列表元素原封不动添加进堆
|
||||
this.#maxHeap = nums === undefined ? [] : [...nums];
|
||||
|
@ -9,7 +9,7 @@ const { printTree } = require("../include/PrintUtil");
|
||||
|
||||
/* AVL 树*/
|
||||
class AVLTree {
|
||||
/*构造函数*/
|
||||
/*构造方法*/
|
||||
constructor() {
|
||||
this.root = null; //根结点
|
||||
}
|
||||
@ -98,7 +98,7 @@ class AVLTree {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
insertHelper(node, val) {
|
||||
if (node === null) return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入结点 */
|
||||
@ -118,7 +118,7 @@ class AVLTree {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
removeHelper(node, val) {
|
||||
if (node === null) return null;
|
||||
/* 1. 查找结点,并删除之 */
|
||||
|
@ -10,7 +10,7 @@ from include import *
|
||||
|
||||
""" 列表类简易实现 """
|
||||
class MyList:
|
||||
""" 构造函数 """
|
||||
""" 构造方法 """
|
||||
def __init__(self):
|
||||
self.__capacity = 10 # 列表容量
|
||||
self.__nums = [0] * self.__capacity # 数组(存储列表元素)
|
||||
|
@ -89,7 +89,7 @@ class AVLTree:
|
||||
self.root = self.__insert_helper(self.root, val)
|
||||
return self.root
|
||||
|
||||
""" 递归插入结点(辅助函数)"""
|
||||
""" 递归插入结点(辅助方法)"""
|
||||
def __insert_helper(self, node: Optional[TreeNode], val: int) -> TreeNode:
|
||||
if node is None:
|
||||
return TreeNode(val)
|
||||
@ -111,7 +111,7 @@ class AVLTree:
|
||||
root = self.__remove_helper(self.root, val)
|
||||
return root
|
||||
|
||||
""" 递归删除结点(辅助函数) """
|
||||
""" 递归删除结点(辅助方法) """
|
||||
def __remove_helper(self, node: Optional[TreeNode], val: int) -> Optional[TreeNode]:
|
||||
if node is None:
|
||||
return None
|
||||
|
@ -11,7 +11,7 @@ class MyList {
|
||||
private var _size = 0 // 列表长度(即当前元素数量)
|
||||
private let extendRatio = 2 // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
init() {
|
||||
nums = Array(repeating: 0, count: _capacity)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class GraphAdjMat {
|
||||
private var vertices: [Int] // 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
|
||||
private var adjMat: [[Int]] // 邻接矩阵,行列索引对应“顶点索引”
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
init(vertices: [Int], edges: [[Int]]) {
|
||||
self.vertices = []
|
||||
adjMat = []
|
||||
|
@ -10,7 +10,7 @@ import utils
|
||||
class MaxHeap {
|
||||
private var maxHeap: [Int]
|
||||
|
||||
/* 构造函数,根据输入列表建堆 */
|
||||
/* 构造方法,根据输入列表建堆 */
|
||||
init(nums: [Int]) {
|
||||
// 将列表元素原封不动添加进堆
|
||||
maxHeap = nums
|
||||
|
@ -95,7 +95,7 @@ class AVLTree {
|
||||
return root
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
private func insertHelper(node: TreeNode?, val: Int) -> TreeNode? {
|
||||
var node = node
|
||||
if node == nil {
|
||||
@ -123,7 +123,7 @@ class AVLTree {
|
||||
return root
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
private func removeHelper(node: TreeNode?, val: Int) -> TreeNode? {
|
||||
var node = node
|
||||
if node == nil {
|
||||
|
@ -11,7 +11,7 @@ class MyList {
|
||||
private _size: number = 0; // 列表长度(即当前元素数量)
|
||||
private extendRatio: number = 2; // 每次列表扩容的倍数
|
||||
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
constructor() {
|
||||
this.nums = new Array(this._capacity);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class Vertex {
|
||||
/* 基于邻接表实现的无向图类 */
|
||||
class GraphAdjList {
|
||||
adjList: Map<Vertex, Set<Vertex>>;
|
||||
/* 构造函数 */
|
||||
/* 构造方法 */
|
||||
constructor(edges: Vertex[][]) {
|
||||
this.adjList = new Map();
|
||||
// 添加所有顶点和边
|
||||
|
@ -9,7 +9,7 @@ import { printHeap } from "../module/PrintUtil";
|
||||
/* 最大堆类 */
|
||||
class MaxHeap {
|
||||
private maxHeap: number[];
|
||||
/* 构造函数,建立空堆或根据输入列表建堆 */
|
||||
/* 构造方法,建立空堆或根据输入列表建堆 */
|
||||
constructor(nums?: number[]) {
|
||||
// 将列表元素原封不动添加进堆
|
||||
this.maxHeap = nums === undefined ? [] : [...nums];
|
||||
|
@ -10,7 +10,7 @@ import { printTree } from "../module/PrintUtil";
|
||||
/* AVL 树*/
|
||||
class AVLTree {
|
||||
root: TreeNode;
|
||||
/*构造函数*/
|
||||
/*构造方法*/
|
||||
constructor() {
|
||||
this.root = null; //根结点
|
||||
}
|
||||
@ -99,7 +99,7 @@ class AVLTree {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
/* 递归插入结点(辅助函数) */
|
||||
/* 递归插入结点(辅助方法) */
|
||||
insertHelper(node: TreeNode, val: number): TreeNode {
|
||||
if (node === null) return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入结点 */
|
||||
@ -123,7 +123,7 @@ class AVLTree {
|
||||
return this.root;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
/* 递归删除结点(辅助方法) */
|
||||
removeHelper(node: TreeNode, val: number): TreeNode {
|
||||
if (node === null) return null;
|
||||
/* 1. 查找结点,并删除之 */
|
||||
|
@ -17,7 +17,7 @@ pub fn MyList(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数(分配内存+初始化列表)
|
||||
// 构造方法(分配内存+初始化列表)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -27,7 +27,7 @@ pub fn MyList(comptime T: type) type {
|
||||
std.mem.set(T, self.nums, @as(T, 0));
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -26,7 +26,7 @@ pub fn ArrayHashMap(comptime T: type) type {
|
||||
|
||||
const Self = @This();
|
||||
|
||||
// 构造函数
|
||||
// 构造方法
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
self.mem_allocator = allocator;
|
||||
// 初始化一个长度为 100 的桶(数组)
|
||||
@ -37,7 +37,7 @@ pub fn ArrayHashMap(comptime T: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
// 析构函数
|
||||
// 析构方法
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.bucket != null) self.bucket.?.deinit();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ pub fn MaxHeap(comptime T: type) type {
|
||||
|
||||
maxHeap: ?std.ArrayList(T) = null, // 使用列表而非数组,这样无需考虑扩容问题
|
||||
|
||||
// 构造函数,根据输入列表建堆
|
||||
// 构造方法,根据输入列表建堆
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator, nums: []const T) !void {
|
||||
if (self.maxHeap != null) return;
|
||||
self.maxHeap = std.ArrayList(T).init(allocator);
|
||||
@ -25,7 +25,7 @@ pub fn MaxHeap(comptime T: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
// 析构函数,释放内存
|
||||
// 析构方法,释放内存
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.maxHeap != null) self.maxHeap.?.deinit();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub fn ArrayQueue(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数(分配内存+初始化数组)
|
||||
// 构造方法(分配内存+初始化数组)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator, cap: usize) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -28,7 +28,7 @@ pub fn ArrayQueue(comptime T: type) type {
|
||||
std.mem.set(T, self.nums, @as(T, 0));
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -12,14 +12,14 @@ pub fn ArrayStack(comptime T: type) type {
|
||||
|
||||
stack: ?std.ArrayList(T) = null,
|
||||
|
||||
// 构造函数(分配内存+初始化栈)
|
||||
// 构造方法(分配内存+初始化栈)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) void {
|
||||
if (self.stack == null) {
|
||||
self.stack = std.ArrayList(T).init(allocator);
|
||||
}
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.stack == null) return;
|
||||
self.stack.?.deinit();
|
||||
|
@ -34,7 +34,7 @@ pub fn LinkedListDeque(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数(分配内存+初始化队列)
|
||||
// 构造方法(分配内存+初始化队列)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -45,7 +45,7 @@ pub fn LinkedListDeque(comptime T: type) type {
|
||||
self.deqSize = 0;
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -16,7 +16,7 @@ pub fn LinkedListQueue(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数(分配内存+初始化队列)
|
||||
// 构造方法(分配内存+初始化队列)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -27,7 +27,7 @@ pub fn LinkedListQueue(comptime T: type) type {
|
||||
self.queSize = 0;
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -15,7 +15,7 @@ pub fn LinkedListStack(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数(分配内存+初始化栈)
|
||||
// 构造方法(分配内存+初始化栈)
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -25,7 +25,7 @@ pub fn LinkedListStack(comptime T: type) type {
|
||||
self.stkSize = 0;
|
||||
}
|
||||
|
||||
// 析构函数(释放内存)
|
||||
// 析构方法(释放内存)
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -14,7 +14,7 @@ pub fn AVLTree(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数
|
||||
// 构造方法
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator) void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -22,7 +22,7 @@ pub fn AVLTree(comptime T: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
// 析构函数
|
||||
// 析构方法
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
@ -113,7 +113,7 @@ pub fn AVLTree(comptime T: type) type {
|
||||
return self.root;
|
||||
}
|
||||
|
||||
// 递归插入结点(辅助函数)
|
||||
// 递归插入结点(辅助方法)
|
||||
fn insertHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) !?*inc.TreeNode(T) {
|
||||
var node = node_;
|
||||
if (node == null) {
|
||||
@ -142,7 +142,7 @@ pub fn AVLTree(comptime T: type) type {
|
||||
return self.root;
|
||||
}
|
||||
|
||||
// 递归删除结点(辅助函数)
|
||||
// 递归删除结点(辅助方法)
|
||||
fn removeHelper(self: *Self, node_: ?*inc.TreeNode(T), val: T) ?*inc.TreeNode(T) {
|
||||
var node = node_;
|
||||
if (node == null) return null;
|
||||
|
@ -14,7 +14,7 @@ pub fn BinarySearchTree(comptime T: type) type {
|
||||
mem_arena: ?std.heap.ArenaAllocator = null,
|
||||
mem_allocator: std.mem.Allocator = undefined, // 内存分配器
|
||||
|
||||
// 构造函数
|
||||
// 构造方法
|
||||
pub fn init(self: *Self, allocator: std.mem.Allocator, nums: []T) !void {
|
||||
if (self.mem_arena == null) {
|
||||
self.mem_arena = std.heap.ArenaAllocator.init(allocator);
|
||||
@ -24,7 +24,7 @@ pub fn BinarySearchTree(comptime T: type) type {
|
||||
self.root = try self.buildTree(nums, 0, nums.len - 1); // 构建二叉搜索树
|
||||
}
|
||||
|
||||
// 析构函数
|
||||
// 析构方法
|
||||
pub fn deinit(self: *Self) void {
|
||||
if (self.mem_arena == null) return;
|
||||
self.mem_arena.?.deinit();
|
||||
|
@ -41,120 +41,37 @@ comments: true
|
||||
=== "C++"
|
||||
|
||||
```cpp title="graph_adjacency_matrix.cpp"
|
||||
|
||||
[class]{GraphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="graph_adjacency_matrix.py"
|
||||
|
||||
[class]{GraphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="graph_adjacency_matrix.go"
|
||||
/* 基于邻接矩阵实现的无向图类 */
|
||||
type graphAdjMat struct {
|
||||
// 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
|
||||
vertices []int
|
||||
// 邻接矩阵,行列索引对应“顶点索引”
|
||||
adjMat [][]int
|
||||
}
|
||||
|
||||
func newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {
|
||||
// 添加顶点
|
||||
n := len(vertices)
|
||||
adjMat := make([][]int, n)
|
||||
for i := range adjMat {
|
||||
adjMat[i] = make([]int, n)
|
||||
}
|
||||
// 初始化图
|
||||
g := &graphAdjMat{
|
||||
vertices: vertices,
|
||||
adjMat: adjMat,
|
||||
}
|
||||
// 添加边
|
||||
// 请注意,edges 元素代表顶点索引,即对应 vertices 元素索引
|
||||
for i := range edges {
|
||||
g.addEdge(edges[i][0], edges[i][1])
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
/* 获取顶点数量 */
|
||||
func (g *graphAdjMat) size() int {
|
||||
return len(g.vertices)
|
||||
}
|
||||
|
||||
/* 添加顶点 */
|
||||
func (g *graphAdjMat) addVertex(val int) {
|
||||
n := g.size()
|
||||
// 向顶点列表中添加新顶点的值
|
||||
g.vertices = append(g.vertices, val)
|
||||
// 在邻接矩阵中添加一行
|
||||
newRow := make([]int, n)
|
||||
g.adjMat = append(g.adjMat, newRow)
|
||||
// 在邻接矩阵中添加一列
|
||||
for i := range g.adjMat {
|
||||
g.adjMat[i] = append(g.adjMat[i], 0)
|
||||
}
|
||||
}
|
||||
|
||||
/* 删除顶点 */
|
||||
func (g *graphAdjMat) removeVertex(index int) {
|
||||
if index >= g.size() {
|
||||
return
|
||||
}
|
||||
// 在顶点列表中移除索引 index 的顶点
|
||||
g.vertices = append(g.vertices[:index], g.vertices[index+1:]...)
|
||||
// 在邻接矩阵中删除索引 index 的行
|
||||
g.adjMat = append(g.adjMat[:index], g.adjMat[index+1:]...)
|
||||
// 在邻接矩阵中删除索引 index 的列
|
||||
for i := range g.adjMat {
|
||||
g.adjMat[i] = append(g.adjMat[i][:index], g.adjMat[i][index+1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
/* 添加边 */
|
||||
// 参数 i, j 对应 vertices 元素索引
|
||||
func (g *graphAdjMat) addEdge(i, j int) {
|
||||
// 索引越界与相等处理
|
||||
if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {
|
||||
fmt.Errorf("%s", "Index Out Of Bounds Exception")
|
||||
}
|
||||
// 在无向图中,邻接矩阵沿主对角线对称,即满足 (i, j) == (j, i)
|
||||
g.adjMat[i][j] = 1
|
||||
g.adjMat[j][i] = 1
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
// 参数 i, j 对应 vertices 元素索引
|
||||
func (g *graphAdjMat) removeEdge(i, j int) {
|
||||
// 索引越界与相等处理
|
||||
if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {
|
||||
fmt.Errorf("%s", "Index Out Of Bounds Exception")
|
||||
}
|
||||
g.adjMat[i][j] = 0
|
||||
g.adjMat[j][i] = 0
|
||||
}
|
||||
[class]{graphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="graph_adjacency_matrix.js"
|
||||
|
||||
[class]{GraphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="graph_adjacency_matrix.ts"
|
||||
|
||||
[class]{GraphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="graph_adjacency_matrix.c"
|
||||
|
||||
[class]{graphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
@ -166,83 +83,7 @@ comments: true
|
||||
=== "Swift"
|
||||
|
||||
```swift title="graph_adjacency_matrix.swift"
|
||||
/* 基于邻接矩阵实现的无向图类 */
|
||||
class GraphAdjMat {
|
||||
private var vertices: [Int] // 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
|
||||
private var adjMat: [[Int]] // 邻接矩阵,行列索引对应“顶点索引”
|
||||
|
||||
/* 构造函数 */
|
||||
init(vertices: [Int], edges: [[Int]]) {
|
||||
self.vertices = []
|
||||
adjMat = []
|
||||
// 添加顶点
|
||||
for val in vertices {
|
||||
addVertex(val: val)
|
||||
}
|
||||
// 添加边
|
||||
// 请注意,edges 元素代表顶点索引,即对应 vertices 元素索引
|
||||
for e in edges {
|
||||
addEdge(i: e[0], j: e[1])
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取顶点数量 */
|
||||
func size() -> Int {
|
||||
vertices.count
|
||||
}
|
||||
|
||||
/* 添加顶点 */
|
||||
func addVertex(val: Int) {
|
||||
let n = size()
|
||||
// 向顶点列表中添加新顶点的值
|
||||
vertices.append(val)
|
||||
// 在邻接矩阵中添加一行
|
||||
let newRow = Array(repeating: 0, count: n)
|
||||
adjMat.append(newRow)
|
||||
// 在邻接矩阵中添加一列
|
||||
for i in adjMat.indices {
|
||||
adjMat[i].append(0)
|
||||
}
|
||||
}
|
||||
|
||||
/* 删除顶点 */
|
||||
func removeVertex(index: Int) {
|
||||
if index >= size() {
|
||||
fatalError("越界")
|
||||
}
|
||||
// 在顶点列表中移除索引 index 的顶点
|
||||
vertices.remove(at: index)
|
||||
// 在邻接矩阵中删除索引 index 的行
|
||||
adjMat.remove(at: index)
|
||||
// 在邻接矩阵中删除索引 index 的列
|
||||
for i in adjMat.indices {
|
||||
adjMat[i].remove(at: index)
|
||||
}
|
||||
}
|
||||
|
||||
/* 添加边 */
|
||||
// 参数 i, j 对应 vertices 元素索引
|
||||
func addEdge(i: Int, j: Int) {
|
||||
// 索引越界与相等处理
|
||||
if i < 0 || j < 0 || i >= size() || j >= size() || i == j {
|
||||
fatalError("越界")
|
||||
}
|
||||
// 在无向图中,邻接矩阵沿主对角线对称,即满足 (i, j) == (j, i)
|
||||
adjMat[i][j] = 1
|
||||
adjMat[j][i] = 1
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
// 参数 i, j 对应 vertices 元素索引
|
||||
func removeEdge(i: Int, j: Int) {
|
||||
// 索引越界与相等处理
|
||||
if i < 0 || j < 0 || i >= size() || j >= size() || i == j {
|
||||
fatalError("越界")
|
||||
}
|
||||
adjMat[i][j] = 0
|
||||
adjMat[j][i] = 0
|
||||
}
|
||||
}
|
||||
[class]{GraphAdjMat}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
@ -289,121 +130,49 @@ comments: true
|
||||
=== "C++"
|
||||
|
||||
```cpp title="graph_adjacency_list.cpp"
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python title="graph_adjacency_list.py"
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "Go"
|
||||
|
||||
```go title="graph_adjacency_list.go"
|
||||
/* 顶点类 */
|
||||
type vertex struct {
|
||||
val int
|
||||
}
|
||||
[class]{vertex}-[func]{}
|
||||
|
||||
func newVertex(val int) vertex {
|
||||
return vertex{
|
||||
val: val,
|
||||
}
|
||||
}
|
||||
|
||||
/* 基于邻接表实现的无向图类 */
|
||||
type graphAdjList struct {
|
||||
// 请注意,vertices 和 adjList 中存储的都是 Vertex 对象
|
||||
// 邻接表(使用哈希表实现), 使用哈希表模拟集合
|
||||
adjList map[vertex]map[vertex]struct{}
|
||||
}
|
||||
|
||||
/* 构造函数 */
|
||||
func newGraphAdjList(edges [][]vertex) *graphAdjList {
|
||||
g := &graphAdjList{
|
||||
adjList: make(map[vertex]map[vertex]struct{}),
|
||||
}
|
||||
// 添加所有顶点和边
|
||||
for _, edge := range edges {
|
||||
g.addVertex(edge[0])
|
||||
g.addVertex(edge[1])
|
||||
g.addEdge(edge[0], edge[1])
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
/* 获取顶点数量 */
|
||||
func (g *graphAdjList) size() int {
|
||||
return len(g.adjList)
|
||||
}
|
||||
|
||||
/* 添加边 */
|
||||
func (g *graphAdjList) addEdge(vet1 vertex, vet2 vertex) {
|
||||
_, ok1 := g.adjList[vet1]
|
||||
_, ok2 := g.adjList[vet2]
|
||||
if !ok1 || !ok2 || vet1 == vet2 {
|
||||
panic("error")
|
||||
}
|
||||
// 添加边 vet1 - vet2, 添加匿名 struct{},
|
||||
g.adjList[vet1][vet2] = struct{}{}
|
||||
g.adjList[vet2][vet1] = struct{}{}
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
func (g *graphAdjList) removeEdge(vet1 vertex, vet2 vertex) {
|
||||
_, ok1 := g.adjList[vet1]
|
||||
_, ok2 := g.adjList[vet2]
|
||||
if !ok1 || !ok2 || vet1 == vet2 {
|
||||
panic("error")
|
||||
}
|
||||
// 删除边 vet1 - vet2, 借助 delete 来删除 map 中的键
|
||||
delete(g.adjList[vet1], vet2)
|
||||
delete(g.adjList[vet2], vet1)
|
||||
}
|
||||
|
||||
/* 添加顶点 */
|
||||
func (g *graphAdjList) addVertex(vet vertex) {
|
||||
_, ok := g.adjList[vet]
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
// 在邻接表中添加一个新链表(即 set)
|
||||
g.adjList[vet] = make(map[vertex]struct{})
|
||||
}
|
||||
|
||||
/* 删除顶点 */
|
||||
func (g *graphAdjList) removeVertex(vet vertex) {
|
||||
_, ok := g.adjList[vet]
|
||||
if !ok {
|
||||
panic("error")
|
||||
}
|
||||
// 在邻接表中删除顶点 vet 对应的链表
|
||||
delete(g.adjList, vet)
|
||||
// 遍历其它顶点的链表(即 Set),删除所有包含 vet 的边
|
||||
for _, set := range g.adjList {
|
||||
// 操作
|
||||
delete(set, vet)
|
||||
}
|
||||
}
|
||||
[class]{graphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
|
||||
```javascript title="graph_adjacency_list.js"
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "TypeScript"
|
||||
|
||||
```typescript title="graph_adjacency_list.ts"
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "C"
|
||||
|
||||
```c title="graph_adjacency_list.c"
|
||||
[class]{vertex}-[func]{}
|
||||
|
||||
[class]{graphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "C#"
|
||||
@ -417,91 +186,17 @@ comments: true
|
||||
=== "Swift"
|
||||
|
||||
```swift title="graph_adjacency_list.swift"
|
||||
/* 顶点类 */
|
||||
class Vertex: Hashable {
|
||||
var val: Int
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
init(val: Int) {
|
||||
self.val = val
|
||||
}
|
||||
|
||||
static func == (lhs: Vertex, rhs: Vertex) -> Bool {
|
||||
lhs.val == rhs.val
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(val)
|
||||
}
|
||||
}
|
||||
|
||||
/* 基于邻接表实现的无向图类 */
|
||||
class GraphAdjList {
|
||||
// 请注意,vertices 和 adjList 中存储的都是 Vertex 对象
|
||||
private var adjList: [Vertex: Set<Vertex>] // 邻接表(使用哈希表实现)
|
||||
|
||||
init(edges: [[Vertex]]) {
|
||||
adjList = [:]
|
||||
// 添加所有顶点和边
|
||||
for edge in edges {
|
||||
addVertex(vet: edge[0])
|
||||
addVertex(vet: edge[1])
|
||||
addEdge(vet1: edge[0], vet2: edge[1])
|
||||
}
|
||||
}
|
||||
|
||||
/* 获取顶点数量 */
|
||||
func size() -> Int {
|
||||
adjList.count
|
||||
}
|
||||
|
||||
/* 添加边 */
|
||||
func addEdge(vet1: Vertex, vet2: Vertex) {
|
||||
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
|
||||
fatalError("参数错误")
|
||||
}
|
||||
// 添加边 vet1 - vet2
|
||||
adjList[vet1]?.insert(vet2)
|
||||
adjList[vet2]?.insert(vet1)
|
||||
}
|
||||
|
||||
/* 删除边 */
|
||||
func removeEdge(vet1: Vertex, vet2: Vertex) {
|
||||
if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {
|
||||
fatalError("参数错误")
|
||||
}
|
||||
// 删除边 vet1 - vet2
|
||||
adjList[vet1]?.remove(vet2)
|
||||
adjList[vet2]?.remove(vet1)
|
||||
}
|
||||
|
||||
/* 添加顶点 */
|
||||
func addVertex(vet: Vertex) {
|
||||
if adjList[vet] != nil {
|
||||
return
|
||||
}
|
||||
// 在邻接表中添加一个新链表(即 HashSet)
|
||||
adjList[vet] = []
|
||||
}
|
||||
|
||||
/* 删除顶点 */
|
||||
func removeVertex(vet: Vertex) {
|
||||
if adjList[vet] == nil {
|
||||
fatalError("参数错误")
|
||||
}
|
||||
// 在邻接表中删除顶点 vet 对应的链表(即 HashSet)
|
||||
adjList.removeValue(forKey: vet)
|
||||
// 遍历其它顶点的链表(即 HashSet),删除所有包含 vet 的边
|
||||
for key in adjList.keys {
|
||||
adjList[key]?.remove(vet)
|
||||
}
|
||||
}
|
||||
}
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
||||
```zig title="graph_adjacency_list.zig"
|
||||
[class]{Vertex}-[func]{}
|
||||
|
||||
[class]{GraphAdjList}-[func]{}
|
||||
```
|
||||
|
||||
## 9.2.3. 效率对比
|
||||
|
@ -66,7 +66,7 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
||||
|
||||
def check_func_blong_to_class(label):
|
||||
class_label_pattern = re.compile(f".*\*{label}\).*")
|
||||
func_return_pattern = re.compile(f".*\*{label}.*")
|
||||
func_return_pattern = re.compile(f".*{label}.*")
|
||||
constructor_pattern = re.compile(f".*new.*")
|
||||
|
||||
class_label_match = class_label_pattern.match(f"{func_cls_label}")
|
||||
@ -172,7 +172,7 @@ class ExtractCodeBlocksGo(ExtractCodeBlocksJava):
|
||||
replace_tabs(func)
|
||||
|
||||
|
||||
# for code_path in glob.glob("codes/go/chapter_*/array_hash_map.go"):
|
||||
# ext = ExtractCodeBlocksGo()
|
||||
# res = ext.extract(code_path)
|
||||
# pass
|
||||
for code_path in glob.glob("codes/*/chapter_*/graph_adjacency_matrix.go"):
|
||||
ext = ExtractCodeBlocksGo()
|
||||
res = ext.extract(code_path)
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user