//Filename: showtree.c //Developer: Jay Suttiruttana #include "btree.h" void main(void) { //opens the B-Tree file btopen(); printf("B-Tree:\n\n"); //printf("PAGE FORMAT -> [p0,(PK0),p1,(PK1),p2,(PK2),p3,(PK3),p4]\n\n"); /* pass in the root of the B-Tree */ ShowTree( getroot() ); //close the B-Tree file btclose(); } /******************************************************************************* Function: ShowTree Return type: an integer Task: it it outputs the B-Tree data structure--displaying all pages in the tree. Pre: the rrn has been passed in succesfully. Post: the structure of the B-Tree passed in is output on the screen. In successful of doing that, it returns 1. Otherwise, returns 0. *******************************************************************************/ int ShowTree(int rrn) { page_type page; int i; if(rrn == NIL) return(0); btread(rrn, &page); /* Retrieve current page from B-Tree */ printf("PAGE #%d -> ", rrn); /* Display current page # and the page itself */ if(rrn < 10) printf(" "); if(rrn>=10 && rrn<100) printf(" "); if(rrn>=100) printf(" "); ShowPage(&page); for(i=0; i<=page.keycount&&page.child[i]!=NIL;i++) ShowTree(page.child[i]); /* Show each page in B-Tree */ return(1); } /******************************************************************************* Function: ShowPage Return type: none Task: it it outputs all keys and descendents' RRNs of the given page. Pre: the page is passed in. Post: all keys and descendents' RRNs of the given page are output. *******************************************************************************/ void ShowPage(page_type *p_page) { int i; /* display each key & left child in page */ printf("["); for(i=0;ikeycount;i++) printf("%2d,(%3d),", p_page->child[i], p_page->item[i].key); /* display the last child in page */ printf("%2d]\n", p_page->child[i]); } /*******************************************************************************/