Considere as seguintes três afirmações com base no código:I...
Imagem de fundo

Considere as seguintes três afirmações com base no código:I...

Utilize o código fonte em linguagem C seguinte para responder as questões 45 e 46.


#include <stdio.h>

#include <stdlib.h>


struct Node {

int data;

struct Node* left;

struct Node* right;

};

struct Node* createNode(int data) {

struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));

newNode->data = data;

newNode->left = NULL;

newNode->right = NULL;

return newNode;

}

struct Node* insert(struct Node* root, int data)(

if (root == NULL) {

return createNode(data);

}

if (data < root->data) (

root->left = insert(root->left, data);

Y else if (data > root->data) £

root->right = insert(root->right, data);

}

return root;

}

struct Node* search(struct Node* root, int key) {

if (root == NULL || root->data == key){

return root;

}

if (key < root->data) (

return search(root->left, key);

}

return search(root->right, key);

}

void list(struct Node* root) {

if (root != NULL) {

list(root->left);

printf("%d ”, root->data);

list(root->right);

}

}

int main() {

struct Node* root = NULL;

root = insert(root, 50);

root = insert(root, 20);

root = insert(root, 70);

root = insert(root, 20);

root = insert(root, 50);

list(root);

return 0;

}

Considere as seguintes três afirmações com base no código:


I - A função list() percorre a árvore e imprime os elementos em ordem crescente.

II - A função search() realiza uma busca recursiva na árvore binária e retorna um ponteiro para o nó que contém o elemento procurado, se encontrado.

III - A função list() não é recursiva.


Assinale a alternativa correta:


A

Apenas a afirmação I é correta.


B

As afirmações l e Il são corretas.


C

Apenas a afirmação Il é correta.


D

As afirmações l e Ill são corretas.


E

As afirmações Il e Ill são corretas.