SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Science Posted 08 Nov 2017 My Price 10.00

I have completed most of this assignment but I am struggling with the "main() " part of the file...

#include<stdlib.h>#include<stdio.h>#include<malloc.h>#define HEIGHT 1struct node {int data;struct node* left;struct node* right;int height;};struct node* get_node(int val) {struct node* new_node = (struct node*)malloc(sizeof(struct node));new_node->left = NULL;new_node->right = NULL;new_node->data = val;new_node->height = HEIGHT;return new_node;}int get_height(struct node* root) {if(!root)return 0;elsereturn root->height;}int get_balance(struct node* root) {if(!root)return 0;return (get_height(root->left) - get_height(root->right));}int max(int a, int b) {return (a > b) ? a : b;}struct node* left_rotate(struct node* root) {struct node* right = root->right;struct node* left = right->left;right->left = root;root->right = left;root->height = max(get_height(root->left), get_height(root->right)) + 1;right->height = max(get_height(right->left), get_height(right->right)) + 1;return right;}struct node* right_rotate(struct node* root) {struct node* left = root->left;struct node* right = left->right;left->right = root;root->left = right;root->height = max(get_height(root->left), get_height(root->right)) + 1;left->height = max(get_height(left->left), get_height(left->right)) + 1;return left;}
Background image of page 1
struct node* insert(struct node* root, int val) {if(!root) {struct node* new_node = get_node(val);return new_node;}if(root->data > val) {root->left = insert(root->left, val);}elseroot->height = max(get_height(root->left), get_height(root->right)) + 1;int balance = get_balance(root);if(balance > 1 && root->left->data > val) {root = right_rotate(root);}else if(balance < -1 && root->right->data < val) {root = left_rotate(root);}else if(balance > 1 && root->left->data < val) {root->left = left_rotate(root->left);root = right_rotate(root);}else if(balance < -1 && root->right->data > val) {root->right = right_rotate(root->right);root = left_rotate(root);}return root;}struct node* balance_tree(struct node* root) {struct node* x, *y;int lheight,rheight;lheight = get_height(root->left);rheight = get_height(root->right);if(lheight >= rheight)x = root->left;elsex = root->right;lheight = get_height(x->left);rheight = get_height(x->right);if(x == root->left) {if(lheight >= rheight)y = x->left;elsey = x->right;}if(x == root->right) {if(lheight > rheight)y = x->left;elsey = x->right;}
Background image of page 2

Answers

(5)
Status NEW Posted 08 Nov 2017 10:11 AM My Price 10.00

----------- He-----------llo----------- Si-----------r/M-----------ada-----------m -----------Tha-----------nk -----------you----------- fo-----------r y-----------our----------- in-----------ter-----------est----------- an-----------d b-----------uyi-----------ng -----------my -----------pos-----------ted----------- so-----------lut-----------ion-----------. P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll -----------be -----------qui-----------ckl-----------y

Not Rated(0)