c - 有人可以告诉我的树功能有什么问题吗
问题描述
我有一棵树,我需要编写一个函数,在每个偶数根层中它必须包含一个偶数值,并且在每个奇数根层中它必须包含奇数值,左侧的奇数值也必须是该值的 3 次幂( value^3) 如果语句正确,则右侧奇数值和右侧偶数值的奇数值应大于左侧偶数值,则该函数应返回 1,否则返回 0;
在代码下方会有一张我的意思的图片。
这是我的代码:
typedef struct node { int value; struct node *left; struct node *right; } node; int main() { node *root; int even_odd=0; printf("create a tree:\n"); root=create();/*the function to get the user input*/ i=0; even_odd=evenodd(root,0); if ( even_odd) { printf("the tree is an amazing tree\n"); } return 0; } int evenodd(node *root, int n) { int check1=0,check2=0,counter=0,true1=0,true2=0; if(root == NULL) { return 0; } else if(root->left == NULL && root->right == NULL) { return 0; } else { if (root->right != NULL && root->right && root->left) { counter++; check1=evenodd(root->left,root->value); check2=evenodd(root->right,root->value); if (counter % 2 == 0) { if ((check2 %2==0 && check1%2==0) && check2>check1) { true1=1; } } else if (counter %2 != 0) { if ((check2 %2!=0 && check1%2!=0) && pow(check2,3) > check1) { true2=1; } } return (true1 && true2); /*the function returns 1*/ } } }
解决方案
推荐阅读
- ios - 我正在尝试将 UICollectionView 项中的值传递给 Swift 4 中的 UIButton
- javascript - 在shopify中使用嵌入式应用程序获取商店名称/ URL(应用程序是iFramed)
- plot - 用 gfortran 编译 plplot
- .htaccess - 如何使用 Htaccess 从 URL 中删除连续重复的单词?
- excel - 如何在 LINK 字段中调整图形对象的大小?
- php - 组合动态数组
- sql - 选择 In with invalid field
- android - 在 Android 上禁用对 USB 存储的访问
- c++ - SFML 游戏中的逻辑错误,如何修复渲染机制?
- r - 在 R 中保留最近的重复行