uint64 ScheduleStrategy::current() const { enum { t_add = ScheduleStrategy::arithmetic_schedule, t_luby = ScheduleStrategy::luby_schedule }; if (base == 0) return UINT64_MAX; else if (type == t_add) return static_cast<uint64>(addR(idx, grow) + base); else if (type == t_luby)return static_cast<uint64>(lubyR(idx)) * base; uint64 x = static_cast<uint64>(growR(idx, grow) * base); return x + !x; }
int main() { struct semaphore S1={1,0,0}; while(1) { system("cls"); printf("Options :-\n1.Add Reader.\n2.Add Writer.\n3.Remove Reader.\n4.Remove Writer.\n5.Exit.\n\n\tChoice : "); intch; scanf("%d",&ch); switch(ch) { case 1: addR(&S1); break; case 2: addW(&S1); break; case 3: remR(&S1); break; case 4: remW(&S1); break; case 5: printf("\n\tGoodBye!"); getch(); return 0; default: printf("\nInvalid Entry!"); continue; } printf("\n\n<<<<<< Current Status >>>>>>\n\n\tMutex\t\t:\t%d\n\tActive Readers\t:\t%d\n\tWaiting Readers\t:\t%d\n\tWriter Active\t:\t%s\n\n", S1.mutex, S1.rcount, S1.rwait, (S1.mutex==0 && S1.rcount==0) ? "YES" : "NO"); system("pause"); } }
void search() { initMethodF(); initMethodR(); minVariance=1e10; while(true) { if(methodF[F-1]*methodR[R-1]>=3*methodF[0]*methodR[0]) { sort(); } if(not addF()) { initMethodF(); if(not addR()) { break; } } } }
int main(int argc, char** argv){ int nodeCount = 10; if(argc > 1) nodeCount = atoi(argv[1]); bNode *a = NULL; Tree tree=(&a); /* printf("instantiate tree..\n"); printf("Adding elements using addL\n"); for(int i = 10;i >= 0; i--) addL(tree,i); printf("Tree:\n"); drawtree(tree); printf("Now removing all elements from the tree\n"); while (size(tree)) { printf("--remvR--\n"); remvR(tree); printf("Tree:\n"); drawtree(tree); } */ printf("--------------------------\n"); printf("Adding elements using addL\n"); printf("--------------------------\n"); for(int i = 0;i < nodeCount; i++){ printf("Adding %i using addL\n",i); addL(tree,i); printf("Tree:\n"); printaslist(tree); drawtree(tree); printf("\n\n"); } printf("--------------------------\n"); printf(" Testing lookup \n"); printf("--------------------------\n"); printf("Current tree as list:\n"); printaslist(tree); for(int i = 0; i < size(tree); i++) printf("lookup: tree[%i] == %i\n",i,(int)lookup(tree,i)); printf("-------------------------------\n"); printf("Remove all elements using remvR\n"); printf("-------------------------------\n"); while (size(tree)) { remvR(tree); printf("Tree:\n"); printaslist(tree); drawtree(tree); printf("\n\n"); } printf("--------------------------\n"); printf("Adding elements using addR\n"); printf("--------------------------\n"); for(int i = 0;i < nodeCount; i++){ printf("Adding %i using addR\n",i); addR(tree,i); printf("Tree:\n"); printaslist(tree); drawtree(tree); printf("\n\n"); } printf("-------------------------------\n"); printf("Remove all elements using remvL\n"); printf("-------------------------------\n"); while (size(tree)) { remvL(tree); printf("Tree:\n"); printaslist(tree); drawtree(tree); printf("\n\n"); } return 0; }
main(){ int i, j, opt, opt2, opt3, nRuang, nLantai=3; for(i=0; i<nLantai; i++){ addL(i+1); if(i==0) nRuang=5; else if(i==1) nRuang=2; else nRuang=3; for(j=0; j<nRuang; j++) addR(i+1); } while(true){ printf("Menu:\n1. tambah ruang\n2. hapus ruang\n3. pinjam ruang\n4. kembalikan ruang\n5. lihat ruang\n6. lihat ruang yang dipinjam\n7. tambah lantai\n8. hapus lantai\n9. exit\noption : "); scanf("%d",&opt); if(opt==1) { printf("tambah ke lantai : "); scanf("%d",&opt2); nRuang++; addR(opt2); viewL(true); } else if(opt==2){ printf("delete ruang terakhir pada lantai : "); scanf("%d",&opt2); delR(opt2); viewL(true); } else if(opt==3 || opt==4){ printf("Pilih lantai : "); scanf("%d",&opt2); printf("Pilih ruang : "); scanf("%d",&opt3); if(opt==3) status(opt2, opt3, 1); else status(opt2, opt3, 0); viewL(false); } else if(opt==5) viewL(true); else if(opt==6) viewL(false); else if(opt==7){ nLantai++; addL(nLantai); viewL(true); } else if(opt==8){ nLantai--; delL(); viewL(true); } else break; } getch(); }