plsql - PLSQL - 实现函数,返回树中节点的子节点数
问题描述
我想在 PLSQL 中实现以下功能:https://www.geeksforgeeks.org/number-children-given-node-n-ary-tree/。
有没有办法将 queue.push 用作函数?似乎这是不可能的。
// Function to calculate number
// of children of given node
int numberOfChildren(Node* root, int x)
{
// initialize the numChildren as 0
int numChildren = 0;
if (root == NULL)
return 0;
// Creating a queue and pushing the root
queue<Node*> q;
q.push(root);
while (!q.empty()) {
int n = q.size();
// If this node has children
while (n > 0) {
// Dequeue an item from queue and
// check if it is equal to x
// If YES, then return number of children
Node* p = q.front();
q.pop();
if (p->key == x) {
numChildren = numChildren + p->child.size();
return numChildren;
}
// Enqueue all children of the dequeued item
for (int i = 0; i < p->child.size(); i++)
q.push(p->child[i]);
n--;
}
}
return numChildren;
}
解决方案
推荐阅读
- html - 我的 Bootstrap 4 导航栏在移动视图中没有折叠
- javascript - 如何使用 Javascript 将一个 HTML 页面转换为具有多个页面的 PDF
- java - 为什么在使用泛型时方法覆盖不检查方法签名?
- cookies - 在 youtube-nocookie.com 域中使用 YouTube IFrame Player API 脚本时禁用 cookie
- azure-functions - 事件网格触发 Azure 函数:如何访问已删除 blob 的元数据(用户定义的键、值对)?
- java - 在 Java 中排除 JSON 字符串中的特定字段
- javascript - React 教程 - DOM 更新但不显示在浏览器中?
- javascript - 在momentjs中获取本地日期时间json
- sql - SQL Where at least all specified
- python - 如何在轴的边缘绘制标记而不显示轴外的数据?