void linkedListTest() { ListElement * list = nullptr; print(list); appendList(list, 5); print(list); appendList(list, 6); print(list); appendList(list, 3); print(list); appendList(list, 5); print(list); cleanup(list); print(list); }
void appendList(node * & list, int newDigit) { if (list == nullptr) {//create first element if not present list = new node{newDigit}; } else {//walk through to the end of the list and append appendList(list->next, newDigit); } }
int cs6300::AppendElseList(int listIndex, int expr, int statement) { auto state = FrontEndState::instance(); auto e = state->expressions.get(expr); auto list = state->statementLists.get(statement); return appendList(state->clauses, listIndex, std::make_pair(e, list)); }
void RunnerGUI::showDetails(Q3ListViewItem *item) { if ( item == 0L ) return; QString name = fullName(item); if ( name.endsWith("()") ) name = fullName(item->parent()); Tester *tester = Runner::self()->registry().find(name.local8Bit()); if ( tester == 0L ) return; TestResults *res = 0L; if ( tester->inherits("KUnitTest::SlotTester") ) res = static_cast<SlotTester*>(tester)->results(item->text(g_nameColumn).local8Bit()); else res = tester->results(); if ( tester == 0L ) m_testerWidget->details()->setText("No test found with name: " + fullName(item)); else { Q3TextEdit *te = m_testerWidget->details(); te->clear(); te->append("<qt><a name=\"errors\"><font color=\"#990000\">Errors</font></a>:<br></qt>"); appendList(te, res->errorList()); te->append("<qt><br><hr><font color=\"#c2c939\">Expected to fail</font>:<br></qt>"); appendList(te, res->xfailList()); te->append("<qt><br><hr><font color=\"#BF00B5\">Unexpected Success</font>:<br></qt>"); appendList(te, res->xpassList()); te->append("<qt><br><hr><font color=\"#009900\">Success</font>:<br></qt>"); appendList(te, res->successList()); te->append("<qt><br><hr><font color=\"#F7A300\">Skipped</font>:<br></qt>"); appendList(te, res->skipList()); te->append("<qt><br><hr><font color=\"#000099\">Debug</font>:<br></qt>"); te->append(res->debugInfo()); te->scrollToAnchor("errors"); } }
void sq_startScope(SquirrelContext * sqContext, const char * scopeName){ appendList(sqContext->scopeList, cpyString(scopeName)); char * scopeListStr = sq_fullScopeName(sqContext); printf("start scope %s\n", scopeListStr); free(scopeListStr); //Novo escopo criado sqContext->scopeIdCounter++; }
int main() { List* head, *end; buildList(head,end); for (int i = 0; i < 10; ++i) { appendList(head,end,2 * i); } List* p = lookupList(head, 6); }
void AddNoteDialog::setThread( const Thread & thread ) { mThread = thread; setSubject( mThread.topic() ); setElement( mThread.element() ); setJobs( ThreadList(mThread.job()) ); setBody( mThread.body() ); appendList( mThread.threadNotifies().users() ); if( mThread.isRecord() ) mAttachmentList->addItems( mThread.attachmentFiles() ); mReplyThread = mThread.reply(); }
void linkedListTest() { node * list = nullptr; print(list); std::cout << "↔"; reverseList(list); print(list); for (const auto & elem : {5,1,3,2,4,8,6,9,7}) { appendList(list, elem); print(list); std::cout << "↔"; reverseList(list); print(list); } }
int main() { Words * w1 = newList(10); appendList(w1, "caterpie raichu butterfree"); printList(w1); // caterpie raichu butterfree Words * w2 = newList("charmeleon mewtwo pikachu charmander"); printList(w2); // charmeleon mewtwo pikachu charmander appendList(w2, w1); printList(w2); // charmeleon mewtwo pikachu charmander caterpie raichu butterfree appendList(w2, "abra"); printList(w2); // charmeleon mewtwo pikachu charmander caterpie raichu butterfree abra removeWord(w2, "charmeleon"); printList(w2); // mewtwo pikachu charmander caterpie raichu butterfree abra deleteList(w1); deleteList(w2); return 0; }
void MainWindow::appendList(QString path, QString filePath, QTreeWidgetItem *item) { if (!item) return; if (item->childCount()) { int i; for (i = 0; i < item->childCount(); i++) appendList(path + "/" + item->child(i)->text(0), \ filePath + "/" + item->child(i)->text(0), item->child(i)); } else { QTreeWidgetItem *oItem = new QTreeWidgetItem(outputList); oItem->setText(0, path); oItem->setText(1, filePath); oItem->setIcon(0, item->icon(0)); oItem->setIcon(1, item->icon(0)); } }
void flushList(List *list, List *master) { if (!list || !master) { free(list); list = NULL; return; } DocumentNode *doc; while((doc = popList(list)) != NULL) { DocumentNode *add_doc = copyDoc(doc); appendList(master, add_doc); free(doc); doc = NULL; } }
int main(int args,char ** argv) { int array[] = {1,2,4,7,11,15}; int array_len = sizeof(array)/sizeof(int); ListNode *pHead = NULL; for(int i = 0;i < array_len; ++i) { pHead = appendList(pHead,array[i]); } ListNode *pCur = pHead; while(pCur != NULL) { std::cout<<pCur->value<<std::endl; pCur = pCur->next; } int n = 3; std::cout<<getKthNode(pHead,n)<<std::endl; system("pause"); return 0; }
void deployBullet(World *world, BulletType type) { if (world->counter < world->interval) { world->counter++; return; } else { world->counter = 0; world->interval = randRange(0, (int) (50.0 / world->level.level)); } if (world->level.ammo == 0) { // ammo depleted return; } int count = randRange(15, (int) world->width * (1.0 / 3.0)); if (world->level.ammo < count) { count = world->level.ammo; } world->level.ammo -= count; int i; // gotta make space for our bullets :) Bullet *bullet = malloc(sizeof(Bullet) * count); int range = world->width / 2; int randDelta = randRange(-range, range); DeployTemplateFn templateFn = randomTemplate(); for (i = 0; i < count; i++) { templateFn(i == 0 ? NULL : &bullet[i - 1], &bullet[i], world, i, count, randDelta); bullet[i].c = 'o'; bullet[i].life = 0; bullet[i].recycled = false; bullet[i].type = type; appendList(&world->bullets, &bullet[i]); } }
ListPtr makeList(char **a, int n, ListPtr old, int begin) { ListPtr first, current, next; int i; if(n == 0) return old; first = malloc(sizeof(ListRec)); if(!first) return NULL; first->value = a[0]; first->next = NULL; current = first; for(i = 1; i < n; i++) { next = malloc(sizeof(ListRec)); if(!next) { destroyList(first); return NULL; } next->value = a[i]; next->next = NULL; current->next = next; current = next; } if(begin) { current->next = old; return first; } else { return appendList(old, first); } }
void deployPlayerBullet(World *world) { if (world->player.dep) { world->player.dep = false; } else { return; } if (world->player.ammo > 0) { world->player.ammo--; } else { return; } //locate(1, 4); //printf("ACTUAL %d ammo:%ld\n", 6, world->level.ammo); int count = randRange(3, (int) world->width * (1.0 / 3.0)); if (world->level.ammo < count) { count = world->level.ammo; } world->level.ammo -= count; int i; Bullet *bullet = malloc(sizeof(Bullet) * count); int range = world->width / 2; int randDelta = randRange(-range, range); for (i = 0; i < count; i++) { playerCircleTemplate(i == 0 ? NULL : &bullet[i - 1], &bullet[i], world, i, count, randDelta); bullet[i].c = 'o'; bullet[i].life = 0; bullet[i].recycled = false; bullet[i].type = PLAYER_AMMO; appendList(&world->bullets, &bullet[i]); } }
int cs6300::StatementList(int listIndex, int statementIndex) { auto state = FrontEndState::instance(); return appendList(state->statementLists,listIndex,state->statements,statementIndex); }
int cs6300::IdentList(int listIndex, char *ident) { auto state = FrontEndState::instance(); return appendList(state->idLists,listIndex,ident); }
int cs6300::ArgumentList(int listIndex, int exprIndex) { auto state = FrontEndState::instance(); return appendList(state->actualArguments, listIndex, state->expressions, exprIndex); }
void Playlist::appendList(QList<QUrl> list) { appendList(list,(PlaylistItem*)lastChild()); }
int main(void){ int ret = -1; pthread_t thread_uartRec; int on = 1; //Initialize socket if((sockfd = socket(AF_INET, SOCK_STREAM,0))==-1){ perror("socket"); exit(1); }; bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERV_PORT); if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0){ perror("sockopt error"); exit(1); } if(bind(sockfd, (struct sockaddr *)&servaddr,sizeof(servaddr)) == -1){ perror("bind error"); exit(1); } if(listen(sockfd,10)<0){ perror("listen"); exit(1); } //Initialize UART2 if((uartfd=open_port(uartfd,4)) < 0)//打开串口 3 { perror("open_port error1\n"); exit(1); } if((ret=set_opt(uartfd,9600,8,'N',1)) < 0)//设置串口 9600 8 N 1 { perror("set_opt error1\n"); exit(1); } /*Initialize list*/ clientListHead = initList(); /*Intialize semaphore*/ ret = sem_init(&uart_sem, 0, 1); if(ret == -1){ perror("semaphore create fail!"); exit(EXIT_FAILURE); } ret = pthread_create (&thread_uartRec, NULL, (void*)(&pthread_UART2WiFi), NULL); if (ret != 0) { perror ("pthread_create error!"); } while(1){ pthread_t thread_id = 0; size_t len = sizeof(struct sockaddr); clifd = accept(sockfd, (struct sockaddr *)&cliaddr, &len); if(clifd < 0){ perror("error accept\n"); } appendList(clifd); /*Create Thread to send CMD from uart to wifi*/ ret = pthread_create (&thread_id, NULL, (void*)(&pthread_wifiUart), (void*)(&clifd)); if (ret != 0) { perror ("pthread_create error!"); } } ret = shutdown(sockfd,SHUT_WR); assert(ret != -1); return 0; }
void MainWindow::generateList() { appendList(root->text() + path->text(), "." + path->text(), tree->currentItem()); }
void startStep() { chkinCounter = 0; if(stage == 0) //Initial distribution of points amongst chares { CkPrintf("The points are being distributed amongst chares. \n"); int tempX,tempY,i,j; double Xcoordinate,Ycoordinate; stage++; for(i=0;i<=7;i++) { for(j=0;j<=7;j++) list[i][j].head = NULL; } int alternator = 0; srand((unsigned)time(NULL)); for(i=0;i<TOTAL_PARTICLES;i++) { Xcoordinate = (double)rand()/(double)RAND_MAX; Ycoordinate = (double)rand()/(double)RAND_MAX; tempX = (Xcoordinate*8); tempY = (Ycoordinate*8); /*if((tempX <= 7) && (tempX >= 1) && (tempY <= 7) && (tempY >= 1)) { if(alternator == 0) { tempX = 0; tempY = 0; } else { tempX = 7; tempY = 7; } alternator = ((alternator + 1)%2); }*/ appendList(tempX,tempY,Xcoordinate, Ycoordinate); } CkPrintf("There are %d particles \n", TOTAL_PARTICLES); for(i=0;i<=7;i++) { for(j=0;j<=7;j++) copyVal(list[i][j],i,j); } } else if((stage>0)&&(stage <TOTAL_STEPS)) { totalParticles = 0; stage++; /*Re-initialized because we want to check for each iteration*/ /*if(++stage % LB_INTERVAL == 0) { CkPrintf("Load balancing for stage: %d \n",stage); pointsProxy.balanceLoad(); } else*/ pointsProxy.shiftPoints(); //Broadcast to all chares. } else if(stage == TOTAL_STEPS) { if(totalParticles == TOTAL_PARTICLES) { CkPrintf("There are still %d particles.\n",totalParticles); CkPrintf("Program finished successfully! \n"); } else CkPrintf("Some particles lost! \n"); CkExit(); } };