SE250:lab-6:sgha014

From Marks Wiki
Revision as of 05:20, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (14 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

task1

visual studio was stuffing up again...as usual...so then i tried using that cygwin thing... then kept getting errors....got help from mark and he was confused too...he said that for some reason it was running out of memory...so we compiled and ran it about 6 times and then for some reason it started working??? which was really weird...

	int heightOfTree;

	Node* node = makeRandomTree(7);
	heightOfTree = height(node);
	printf("height: %d", heightOfTree);

also...whats the differnce between Node* node and Node *node ??? Mark said he didnt know either.

i varied the siz from 0 to 300...went up in 5s

graph

task2

i started off using if statements then the tutor said that wont work and said we hav 2 use a loop

Node* minimum( Node* node ) {
  /* TODO */
	while(node->left != empty){
		node = node->left;
	}
	return node;

}

Node* maximum( Node* node ) {
  /* TODO */
	while(node->right != empty){
		node = node->right;
	}
	return node;
}

i got the minimum and maximum for a tree of size 100 and got a min of 41 and a max of 32757

task3

i was abit unsure about this task at first and it took a while for me to get it. but in the end this is what i got

Node* lookup( int key, Node* node ) {
  /* TODO */
	
	while(node != empty){
		if(key == node->key)
			return node;
		else if (key < node->key)
 			node = node->left;
		else
			node = node->right;
	}			
}

im unsure about how to test it though so i dont know if its actually right