这是一个面试问题.
给出了二叉搜索树,并且交换了两个节点的值.问题是如何在树的单次遍历中找到节点和交换值?
我试图使用下面的代码解决这个问题,但我无法阻止递归,所以我得到分段错误.帮我如何阻止递归.
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdlib.h>
/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
int data;
struct node* left;
struct node* right;
};
/* Helper function that allocates a new node with the
given data and NULL left and right pointers. */
struct node* newNode(int data)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right …Run Code Online (Sandbox Code Playgroud) 我在读什么区别的B/W在C指针变量和引用变量++ 这里的.我得到了一点,而引用共享相同的内存地址,但也占用了堆栈上的一些空间..它共享相同的地址空间是什么意思.请清楚说明如何在c ++中实现引用.
我在这里运行一些代码.我试过了-40 % 3.它给了我输出2.当我在C中执行相同的操作时,我得到:
int i = (-40) % 3
printf("%d", i);
Run Code Online (Sandbox Code Playgroud)
输出是
-1
Run Code Online (Sandbox Code Playgroud)
两种语言如何在内部执行模运算?