bool BinTree<T>::addRec(T &d, Node_T *&p) { if(p) return addRec(d, p->m_pChildren[p->m_dato < d]); Node_T *neo = Node_T(d); p = neo; return true; }
int addRec(int num1,int num2) { if(num2==0) return num1; else return 1+addRec(num1,num2-1); }
int main() { int pilih,num1,num2,number,i; char y; lagi:system("cls"); int data[50]={0}; puts("\tPAP-07"); puts("\t------"); printf("1. addRec\n2. subsRec\n3. mulRec\n4. divRec\n5. powRec\n6. factorial\n7. fibonacci\n8. sumTraversal\n"); pilih=0; while(pilih<1||pilih>8) { printf("Pilih: "); scanf("%d",&pilih); } switch(pilih) { case 1: printf("\tInput num1 dan num2\n"); printf("\tnum1: ");scanf("%d",&num1); printf("\tnum2: ");scanf("%d",&num2); printf("\taddRec(%d,%d) --> %d\n",num1,num2,addRec(num1,num2)); break; case 2: printf("\tInput num1 dan num2\n"); printf("\tnum1: ");scanf("%d",&num1); printf("\tnum2: ");scanf("%d",&num2); printf("\tsubsRec(%d,%d) --> %d\n",num1,num2,subsRec(num1,num2)); break; case 3: printf("\tInput num1 dan num2\n"); printf("\tnum1: ");scanf("%d",&num1); printf("\tnum2: ");scanf("%d",&num2); printf("\tmulRec(%d,%d) --> %d\n",num1,num2,mulRec(num1,num2)); break; case 4: printf("\tInput num1 dan num2\n"); printf("\tnum1: ");scanf("%d",&num1); printf("\tnum2: ");scanf("%d",&num2); printf("\tdivRec(%d,%d) --> %d\n",num1,num2,divRec(num1,num2)); break; case 5: printf("\tInput num1 dan num2\n"); printf("\tnum1: ");scanf("%d",&num1); printf("\tnum2: ");scanf("%d",&num2); printf("\tpowRec(%d,%d) --> %d\n",num1,num2,powRec(num1,num2)); break; case 6: printf("\tInput number\n"); printf("\tnumber: ");scanf("%d",&number); printf("\tfactorial(%d) --> %d\n",number,factorial(number)); break; case 7: printf("\tInput number\n"); printf("\tnumber: ");scanf("%d",&number); printf("\t");fibonacci(number); break; case 8: printf("\tmasukkan nilai 0 untuk berhenti\n"); i=0;do{ printf("\t"); scanf("%d",&data[i]); i++; }while(data[i-1]!=0); printf("\tsumTraversal(data,0) --> %d",sumTraversal(data,0)); break; } printf("\n\nke menu[y/other]: "); fflush(stdin);scanf("%c",&y); if(y=='y') { goto lagi; }system("pause"); }
bool Collectiondb::load ( bool isDump ) { char dname[1024]; // MDW: sprintf ( dname , "%s/collections/" , g_hostdb.m_dir ); sprintf ( dname , "%s" , g_hostdb.m_dir ); Dir d; d.set ( dname ); if ( ! d.open ()) return log("admin: Could not load collection config " "files."); // note it log(LOG_INIT,"admin: Loading collection config files."); // . scan through all subdirs in the collections dir // . they should be like, "coll.main/" and "coll.mycollection/" char *f; while ( ( f = d.getNextFilename ( "*" ) ) ) { // skip if first char not "coll." if ( strncmp ( f , "coll." , 5 ) != 0 ) continue; // must end on a digit (i.e. coll.main.0) if ( ! is_digit (f[gbstrlen(f)-1]) ) continue; // point to collection char *coll = f + 5; // NULL terminate at . char *pp = strchr ( coll , '.' ); if ( ! pp ) continue; *pp = '\0'; // get collnum collnum_t collnum = atol ( pp + 1 ); // add it if ( !addRec ( coll , NULL , 0 , false , collnum , isDump , true ) ) return false; } // note it log(LOG_INIT,"admin: Loaded data for %li collections. Ranging from " "collection #0 to #%li.",m_numRecsUsed,m_numRecs-1); // update the time updateTime(); // don't clean the tree if just dumpin if ( isDump ) return true; // remove any nodes with illegal collnums Rdb *r; //r = g_indexdb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); r = g_posdb.getRdb(); r->m_tree.cleanTree ((char **)r->m_bases); //r = g_datedb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); r = g_titledb.getRdb(); r->m_tree.cleanTree ((char **)r->m_bases); //r = g_revdb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); //r = g_sectiondb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); //r = g_checksumdb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); //r = g_tfndb.getRdb(); //r->m_tree.cleanTree ((char **)r->m_bases); r = g_spiderdb.getRdb(); r->m_tree.cleanTree ((char **)r->m_bases); r = g_doledb.getRdb(); r->m_tree.cleanTree ((char **)r->m_bases); // success return true; }
// . reset a collection // . returns false if failed bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) { // ensure it's not NULL if ( ! coll ) { log(LOG_LOGIC,"admin: Collection name to delete is NULL."); return false; } // now must be "test" only for now if ( strcmp(coll,"test") ) { char *xx=NULL;*xx=0; } // no spiders can be out. they may be referencing the CollectionRec // in XmlDoc.cpp... quite likely. if ( g_conf.m_spideringEnabled || g_spiderLoop.m_numSpidersOut > 0 ) { log("admin: Can not delete collection while " "spiders are enabled or active."); return false; } // do not allow this if in repair mode if ( g_repairMode > 0 ) { log("admin: Can not delete collection while in repair mode."); return false; } // get the CollectionRec for "test" CollectionRec *cr = getRec ( "test" ); // must be there. if not, we create test i guess if ( ! cr ) { log("db: could not get test coll rec"); char *xx=NULL;*xx=0; } // make sure an update not in progress if ( cr->m_inProgress ) { char *xx=NULL;*xx=0; } CollectionRec tmp; // copy it to "tmp" long size = (char *)&(cr->m_END_COPY) - (char *)cr; // do not copy the hashtable crap since you will have to re-init it! memcpy ( &tmp , cr , size ); // sizeof(CollectionRec) ); // delete the test coll now if ( ! deleteRec ( "test" , resetTurkdb ) ) return log("admin: reset coll failed"); // make a collection called "test2" so that we copy "test"'s parms bool status = addRec ( "test" , NULL , 0 , true , // bool isNew , (collnum_t) -1 , // not a dump false , // do not save it! false ); // bail on error if ( ! status ) return log("admin: failed to add new coll for reset"); // get its rec CollectionRec *nr = getRec ( "test" ); // must be there if ( ! nr ) { char *xx=NULL;*xx=0; } // save this though, this might have changed! collnum_t cn = nr->m_collnum; // overwrite its rec memcpy ( nr , &tmp , size ) ; // sizeof(CollectionRec) ); // put that collnum back nr->m_collnum = cn; // set the flag m_needsSave = true; // save it again after copy nr->save(); // and clear the robots.txt cache in case we recently spidered a // robots.txt, we don't want to use it, we want to use the one we // have in the test-parser subdir so we are consistent RdbCache *robots = Msg13::getHttpCacheRobots(); RdbCache *others = Msg13::getHttpCacheOthers(); robots->clear ( cn ); others->clear ( cn ); //g_templateTable.reset(); //g_templateTable.save( g_hostdb.m_dir , "turkedtemplates.dat" ); // repopulate CollectionRec::m_sortByDateTable. should be empty // since we are resetting here. //initSortByDateTable ( coll ); // done return true; }