Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the exercise that chains are defined as in problem 4.6 All function are to be

ID: 3571600 • Letter: I

Question

In the exercise that chains are defined as in problem 4.6 All function are to be implemented by employing Chainletor to traverse a chain.
Do it blow for the case of circularly linked lists : Let X11,x2,...Xbox be the elements of a chain. Each circuit is a integer. Write a C++ function to compute the expression 4. L nunction copy together with an as xi an integer. w Let x 1,x 2 be the elements of a chain. Each is xin a C++ function to compute the expression 30xi xi +5). [Hint: use two iterators to simultaneously traverse the chain. mnet inal.

Explanation / Answer

#include #include struct node { int value; node* left; node* right; }; struct node* root; struct node* insert(struct node* r, int data); void inOrder(struct node* r); void preOrder(struct node* r); void postOrder(struct node* r); int main() { root = NULL; int n, v; printf("How many data's do you want to insert ? "); scanf("%d", &n); for(int i=0; ivalue = data; r->left = NULL; r->right = NULL; } else if(data value){ r->left = insert(r->left, data); } else { r->right = insert(r->right, data); } return r; } void inOrder(struct node* r) { if(r!=NULL){ inOrder(r->left); printf("%d ", r->value); inOrder(r->right); } } void preOrder(struct node* r) { if(r!=NULL){ printf("%d ", r->value); preOrder(r->left); preOrder(r->right); } } void postOrder(struct node* r) { if(r!=NULL){ postOrder(r->left); postOrder(r->right); printf("%d ", r->value); } }