#includeThe file should contain only one function main. main expects two arguments: the first is a -xxxxxx and the second is a string. The -xxxxxx argument does the following. Each x is a digit 0-9. The first x denote the base of the string in the second argument, 2-9 or else 0=base 10 or 1=base 16 (HEX). Subsequent x's are bases for answers. First check that you have two inputs and if you do not, or if the first one does not start with a '-', put up the following error message and exit.#include "NumToString.h" short StringToNum(char*string, long *value, char base); ....
The file t_file is a file of matrices so ReadMatrix can be used to read the file. Read the file into memory and sort the matrices according to the rule below. Then print out a list of numbers separated by spaces. At the end of the list, print a newline so the prompt appears immediately below your list of numbers. The first number is the number in the file of the "smallest" matrix, the next number is the number of the next smallest, etc. The first matrix in the file is number 1.
Given two matrices, matrix1 is less than matrix2 provided
To explain "balanced" requires two notions. The first point is that a binary tree orders the data: everything down the left node comes before the current node; then comes the current node; and finally comes everything down the right node. The function treeprint is an example: it prints the nodes in this order.
There is also the notion of the height of a tree and the level of a node. Level is defined inductively: the root has level 0 and if a node has level n then both the right and left nodes have level n+1 (unless they are NULL). The height of a tree is the maximum level of any node. Notice by definition, if there are x nodes of level n, then there are at most 2x nodes of level n+1.
Two trees are equivalent if they induce the same order on the nodes. A "balanced" tree is a tree with the minimal height for the total number of nodes. It will have 1 node of level 0, 2 nodes of level 1, etc. down to 2^{n-1} nodes of level n-1 and finally it will have however many nodes of level n it needs to get the total right.
It is a theorem that any tree is equivalent to a balanced tree and the point of the exercise is to write a function that finds a balanced tree for a given tree.
Your function should work as follows. It should begin with a pointer to the root of the given tree and should return a pointer to the root of your balanced tree. It should also CHANGE the left&right pointers in the given tree so that the end result is balanced. Your function should make no assumptions about what kind of data is being organized, merely assume that if p points to a node, p->left and p->right point to the left and right nodes below p.
This assignment constitutes the take-home part of the final.
It is due at the start of the final, Friday May 8 at 8am.
I will do a pick-up on Monday, May 4 at 8am and if you have
successfully completed the assignment I will let you know.
Back.