Search Functions in Code

2 篇文章 0 订阅
1 篇文章 0 订阅

Finding functions in scripts, or code, is not easy. Here's some idea.

For C++, because functions needs to be declared in the header file and every functions end with ");", we can search ");" in the code. 

For Python, search "def".

For Java, or C#, it's a bit hard. I still didn't find out a good way. For now, I'm searching ("){", ") {",")\n{")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Here's an example of an interval tree implemented in C: ```c #include <stdio.h> #include <stdlib.h> // Structure to represent an interval struct Interval { int low, high; }; // Structure to represent a node in the interval tree struct Node { struct Interval *interval; int max; struct Node *left, *right; }; // Function to create a new interval tree node struct Node* newNode(struct Interval i) { struct Node* node = (struct Node*)malloc(sizeof(struct Node)); node->interval = (struct Interval*)malloc(sizeof(struct Interval)); node->interval->low = i.low; node->interval->high = i.high; node->max = i.high; node->left = NULL; node->right = NULL; return node; } // Function to insert a new interval into the interval tree struct Node* insert(struct Node* root, struct Interval i) { if (root == NULL) return newNode(i); int l = root->interval->low; if (i.low < l) root->left = insert(root->left, i); else root->right = insert(root->right, i); if (root->max < i.high) root->max = i.high; return root; } // Function to check if two intervals overlap int doOverlap(struct Interval i1, struct Interval i2) { return (i1.low <= i2.high && i2.low <= i1.high); } // Function to search for overlapping intervals in the interval tree void search(struct Node* root, struct Interval i) { if (root == NULL) return; if (doOverlap(*(root->interval), i)) printf("Overlaps with [%d, %d]\n", root->interval->low, root->interval->high); if (root->left != NULL && root->left->max >= i.low) search(root->left, i); search(root->right, i); } // Example usage int main() { struct Interval intervals[] = {{15, 20}, {10, 30}, {17, 19}, {5, 20}, {12, 15}, {30, 40}}; int n = sizeof(intervals) / sizeof(intervals[0]); struct Node* root = NULL; for (int i = 0; i < n; i++) root = insert(root, intervals[i]); struct Interval x = {14, 16}; search(root, x); return 0; } ``` This code implements an interval tree data structure in C. It includes functions to create a new interval tree node, insert an interval into the tree, check if two intervals overlap, and search for overlapping intervals in the tree. The main function provides an example usage of the interval tree.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值