
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The instructions for quiz #5 of the cs2143-2144 data structures course for spring 2012. Students are required to implement certain functions for a binary tree class, including insertion, finding values, checking if a node is a leaf, finding the height, finding a parent node, and finding a cousin node.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

class btree { protected: int *p; // array of values int *f; // array of flag unsigned int size;
public: btree(unsigned int s) { int i; p = new int [s]; f = new int [s]; size = s; for (i=0; i<s; ++i) f[i] = 0; }
int insert(int v); //insert value v in the first available empty node of the tree, and // return 1 if it is inserted properly, otherwise return 0 int Find(int v); // Fin value element v node in the binary tree. if found //return the index of the location where it is found. Otherwise, //return - int isLeaf(int i); // return TRUE (1) if the node with index i is a leaf, otherwise // return FALSE (0) int Height() // find and return height of the tree which has been built
int findParent(int v) // find the index of the parent node of the node with index v, //return -1 if the node does not have a parent. int findCousine(int v) // find index of the cousin of the node with index v (whose // grandparent is same (grand parent of v and its cousins //will be same. it means maximum a node in binary tree //can have three cousins. };