foo = [x for x in bar if x.occupants > 1]
Run Code Online (Sandbox Code Playgroud)
谷歌搜索和搜索后,无法弄清楚这是做什么的.也许我没有找到合适的东西但是在这里.非常感谢任何改写这种速记的输入.
好的,所以我有一个只使用C结构和指针构建的二进制搜索树,因为我疯了,不想使用C++.无论如何,我有一些严重的内存泄漏,因为我假设 free(tree),树是下面结构的一个实例,并没有释放那棵树的所有孩子.
这是我的节点:
struct node{
struct node* parent;
struct node* left;
struct node* right;
int key; //the value of the node
};
Run Code Online (Sandbox Code Playgroud)
这是我的bst:
struct bst{
struct node* root;
int elements; //number of nodes in the bst
};
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有没有比递归调用删除函数更好的方法呢?例如(在现场写这篇文章):
void delete_tree(struct node* n){
if(n == NULL) return;
struct node* left = n->left;
struct node* right = n->right;
free(n);
delete_tree(left);
delete_tree(right);
}
Run Code Online (Sandbox Code Playgroud)