Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Tasks Please change this c code to java and answer this question in java. If the coding are to hard to do just answer the
Tasks Please change this c code to java and answer this question in java. If the coding are to hard to do just answer the question. - Write pseudocode for the four methods and possibly for auxiliary methods that you will need. Explain the ideas behind those methods. - Implement the methods within a Java class Tree. - Test your implementation and report on the tests. List keysAtDepth(int d): returns a linked list, which was imple- mented as a part of your Assignment 7, with exactly those integers that occur at depth d in the tree, ordered as they appear from left to right in the tree; if there are no nodes at depth d, return an empty list. Make sure that the algorithm is as efficient as possible, that is, look only at nodes with depth at most d and restrict list operations to one insertion per integer to be inserted. Hint: Note that there may be a name clash if you make the class Node of lists visible outside of List. \#include typedef struct Node \{ int key; struct Node* left; struct Node* right; struct Node parent; \} Node; typedef struct Tree \{ Node* root; \} Tree; typedef struct List \{ int key; struct List* next; \} List; Tree createTree() \{ Tree tree =( Tree ) malloc(sizeof(Tree ) ); tree->root = NULL; return tree; \} Node* createNode(int key) \{ Node node =( Node ) malloc(sizeof(Node )); node > key = key; node->left = NULL; node->right = NULL; node->parent = NULL; return node; \} List* createList() List* list = (List* ) malloc(sizeof(List)); list->key = 0; list->next = NULL; return list; \} void insert(Tree* tree, int key) \{ Node newNode = createNode(key); if (tree->root == NULL) \{ \} else \{ list = keysAtDepth(node->left, d, currDepth+1, list); list = keysAtDepth(node->right, d, currDepth+1, list); \} return list; \} void printlist(List * list) \{ while (list I= NULL) printf("\%d ", list->key); list = list->next; \} printf("' "); \} int main() Tree* tree = createTree(); int n, key, depth; printf("Please enter the number of nodes: "); scanf("%d,&n); for(int i=0;iroot, depth, 0 , list); printf("Elements at depth \%d: ", depth); printList(list); return 0; \}<>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started