//Syed Rais AHmad //Assignment # 9 Question 1 #include "stdafx.h" #include #include #define ORDER 3 //class Node of a multiway tree of order 3; class mtNode { public: int info[ORDER-1]; mtNode * subTree[ORDER]; mtNode(); bool IsEmpty(); bool IsLeaf(); int InsertInNode(int n); }; mtNode::mtNode() { int i=0; for(i=0;iIsEmpty()) { for(i=0;iinfo[i]) { if (!ptr->subTree[i]) ptr->subTree[i]=new mtNode; ptr=ptr->subTree[i]; last=false; } } if (last) {if (!ptr->subTree[i]) ptr->subTree[i]=new mtNode;ptr=ptr->subTree[i];} last=true; } ptr->InsertInNode(n); } mtNode* Tree::Search(int n) { mtNode* ptr=root,*father=NULL; bool found=false; int i=0,index=0; while (ptr) { for(i=0;iinfo[i]==n) { if (ptr->IsLeaf()) father->subTree[index]=NULL; else { while(!ptr->IsLeaf()) { ptr->info[i]=ptr->subTree[i+1]->info[0]; father=ptr; ptr=ptr->subTree[i+1]; } father->subTree[i+1]=NULL; } return NULL; } for(i=0;iinfo[i]) { index=i; father=ptr; ptr=ptr->subTree[i]; break; } } if (i==ORDER-1) {father=ptr;index=i;ptr=ptr->subTree[i];} } return NULL; } Tree::Delete(int n) { //if key is in leaf node delete it. //otherwise replace it with leftmost key of its next-right subtree. //continue until hitting leaf node. //cout << Search(3)->IsLeaf(); } main() { Tree t; int j=0; t.Insert(20); t.Insert(33); t.Insert(1); t.Insert(2); t.Insert(3); cout << t.Search(2)->IsLeaf(); return 0; }