SE250:lab-6:sbas046

From Marks Wiki
Jump to navigation Jump to search

Task 1

I looped 200 times, each time incrementing the size by 5. I printed the results and plotted a graph in Excel.

Graph

Link to graph

Code

int main(){
	
	int h, i;
	Node *randomTree;
	printf("Size, Height\n");


	for (i = 0; i < 1000; i=i+5){
	randomTree = makeRandomTree(i);
	h = height(randomTree);
	printf("%d\n", h);
	}

	return 0;
}

Task 2

Minimum Function

Node* minimum( Node* node ) {
	if (node == empty)
		return node;
	for (; node->left != empty; node = node->left);
	return node;
}

Maximum Function

Node* maximum( Node* node ) {
	if (node == empty)
		return node;
	for (; node->right != empty; node = node->right);
	return node;
}


Task 3

Lookup Function

Node* lookup( int key, Node* node ) {

	while(node != empty){
		if (node == empty)
			return node;

		if (node->key == key){
			return node;
		}else if(node->key < key){
			node = node->right;
		}else{
			node = node->left;
		}
	}
}