CSc 17 Test 2 20 November 2000 >>>>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<, 1. (20 pts) Assume the class LinkList below. Write a member function of LinkList called same() which returns true if and only if two linked lists have the same data in the same order. Given the declaration LinkList a,b;, the call to same() would be a.same(b); (or b.same(a);). (You need not provide the prototype for same()) class LinkList{ private: class Link{ public: Link(); Link(int x); int key; Link *next; }; Link *root; public: ... ... }; bool LinkList::same(LinkList &list){ Link *one,*two; one=root; two=list.root; while(one!=NULL && two!=NULL && one->key==two->key){ one=one->next; two=two->next; } return one==NULL && two==NULL; } 2. (25 pts) For the class X below overload the operators "+" and "<<". When we have the declaration X a,b; a+b should return an instance of X whose data member x contains the sum of the x's of a and b, and if a.x=4, cout<max) max=count; getch(fin,ch); } return max; } 5. (20 pts) Assume the class Tree below. Write a member function product() which returns the product of the entries in the tree. Given the declaration Tree a; the call to product would be a.product();. The function product() may call other functions which you write. class Tree{ private: class Node{ public: Node(); Node(int x); int key; Node *child[2]; }; Node *root; public: ... ... }; int Tree::product(){ return product(root); } int Tree::product(Node *rt){ if(rt==NULL) return 1; else return rt->key*product(rt->child[0])*product(rt->child[1]); }