int main(void){ LS n; int i = 0; int e = 3; printf("%d\n",EmptyList(&n)); while(scanf("%d",&(n.data[i]))) i++; n.length = i; InsertElem(&n,2,0); for (int i=0;i<n.length;i++){ printf("%d\n",n.data[i]); } printf("%d\n",EmptyList(&n)); RemoveElem(&n,2,&e); for (int i=0;i<n.length;i++){ printf("%d\n",n.data[i]); } printf("%d\n",e); printf("%d\n",EmptyList(&n)); GetElem(&n,2,&e); for (int i=0;i<n.length;i++){ printf("%d\n",n.data[i]); } printf("%d\n",e); printf("%d\n",EmptyList(&n)); printf("%d\n",LoctElem(&n,e)); ClearList(&n); printf("%d\n",EmptyList(&n)); getchar(); }
void DataGloveLogger::AssignGloves(DataGloveThreadList & assigned) const { DataGloveThreadList available; GetGloves(available); ParamRef handedness = Parameter("DataGloveHandedness"); int nGlovesRequested = handedness->NumValues(); for(int iRequest = 0; iRequest < nGlovesRequested; iRequest++) { string sWanted = handedness(iRequest); int hWanted; DataGloveThread *found = NULL; if( sWanted == "L" || sWanted == "l" || sWanted == "left" || sWanted == "LEFT" || sWanted == "0") hWanted = FD_HAND_LEFT; else if(sWanted == "R" || sWanted == "r" || sWanted == "right" || sWanted == "RIGHT" || sWanted == "1") hWanted = FD_HAND_RIGHT; else { EmptyList(available); EmptyList(assigned); bcierr << "unrecognized DataGloveHandedness string \"" << sWanted << "\"" << endl; } for(DataGloveThreadList::iterator g=available.begin(); g != available.end(); g++) { if( (*g)->GetHandedness() == hWanted ) { found = *g; break; } } if(found) { available.remove(found); assigned.push_back(found); found->SetIndex(iRequest+1); } else { EmptyList(available); EmptyList(assigned); bcierr << "could not find a match for requested glove #" << iRequest+1 << " (handedness requested: " << sWanted << ")" << endl; } } EmptyList(available); }
int main() { List plist; char ch; InitalizeList(&plist); if (ListIsFull(&plist)) { fprintf(stderr,"List is full!\n"); exit(EXIT_FAILURE); } while((ch = menu()) != 'q') { switch(ch) { case 'a': AddItem(&plist); break; case 'd': deleteItem(&plist); break; case 's': show(&plist); break; default: puts("Error inputing!"); break; } } EmptyList(&plist); puts("Thanks for using!"); return 0; }
global void KillAllSounds() { Sound *sn; Handle theHandle; /* Stop and delete each node in the sound list */ while(!EmptyList(&soundList)) { sn = (Sound *) Native(FirstNode(&soundList)); if (sn->sSample) { audArgs.count = 2; audArgs.func = STOP; audArgs.arg2 = sn->sNumber; KDoAudio ((word *)&audArgs); } else { DoSound(SEnd,(char far *) sn); ResLock(RES_SOUND,sn->sNumber,FALSE); if(theHandle = (Handle) Native(GetProperty((Obj *) Native(sn->sKey), s_handle))) { if ((int)theHandle != 1) { CriticalHandle(theHandle,FALSE); UnlockHandle(theHandle); } } } DeleteNode(&soundList,Pseudo(sn)); } }
Customer* CustomerList::ReturnCustomerPtr(QString userName) { Node<Customer> * traversePtr; if(isEmpty()) { throw EmptyList(); } // NEED TO MAKE SURE 2 ACCOUNT NUMBERS CANNOT BE THE SAME // traversePtr = _head; int index = 0; while (index < _listLimit && traversePtr !=NULL && traversePtr->GetData().getUserName() != userName) { traversePtr = traversePtr->GetNext(); index++; } if (traversePtr == NULL) { // throw exception class if not found. traversePtr = NULL; throw NotFound(); } Customer *dataPtr = traversePtr->GetDataPtr(); return dataPtr; }
int CustomerList::FindCustomerLocation (QString userName) { Node<Customer> * traversePtr; if(isEmpty()) { throw EmptyList(); } // NEED TO MAKE SURE 2 ACCOUNT NUMBERS CANNOT BE THE SAME // traversePtr = _head; int index = 0; while (index < Size() && traversePtr !=NULL && traversePtr->GetData().getUserName() != userName) { traversePtr = traversePtr->GetNext(); index++; } if (traversePtr == NULL) { qDebug() << "12"; // throw exception class if not found. throw NotFound(); } return index; }
Customer CustomerList::operator[](int index) const { Node<Customer> * traversePtr; if(isEmpty()) { throw EmptyList(); } if (index > _listLimit) { throw OutOfRange(); } // NEED TO MAKE SURE 2 ACCOUNT NUMBERS CANNOT BE THE SAME // traversePtr = _head; int i = 0; while (i < _listLimit && traversePtr !=NULL && i != index) { traversePtr = traversePtr->GetNext(); i++; } if (traversePtr == NULL) { // throw exception class if not found. traversePtr = NULL; throw NotFound(); } return traversePtr->GetData(); }
void DataGloveLogger::StopRun() { for(DataGloveThreadList::iterator g = mGloves.begin(); g != mGloves.end(); g++) (*g)->TerminateWait(); EmptyList(mGloves); }
void DataGloveLogger::GetGloves(DataGloveThreadList & available) const { EmptyList(available); int nGloves = CountGloves(); for(int iGlove = 0; iGlove < nGloves; iGlove++) { DataGloveThread *g = new DataGloveThread(this, iGlove, m_deriv); available.push_back(g); string err = g->GetError(); if(err.size()) { EmptyList(available); bcierr << err.c_str() << endl; return; } } }
void nsFrameList::Delete(nsIPresShell* aPresShell) { NS_PRECONDITION(this != &EmptyList(), "Shouldn't Delete() this list"); NS_ASSERTION(IsEmpty(), "Shouldn't Delete() a non-empty list"); aPresShell->FreeByObjectID(nsPresArena::nsFrameList_id, this); }
/* MakeEmpty: * Returns an empty tree */ SearchTree MakeEmpty ( SearchTree T ) { if( T ) { MakeEmpty( T->Left ); MakeEmpty( T->Right ); EmptyList( T->A ); free( T ); } return 0; }/*end MakeEmpty*/ nodeAddr EmptyList ( nodeAddr X ) { if( X ) { EmptyList( X->next ); free( X ); } return 0; }
// LoadBitmap -- Takes the BBitmap and then loads it accordinly into // the list... using the BBitmap constructor of a bitmapNode // DO NOT DELETE the BBitmap when the method returns. It's // mine now. void PictureViewer::LoadBitmap( BBitmap* b ) { if (b == NULL) return; Window()->Lock(); EmptyList(); thePic = b; if ( setup->ViewingMode() == PEEK_IMAGE_WINDOW_TO_IMAGE ) ResizeToImage(); Window()->Unlock(); Refresh(); }
/* MakeEmpty: * Returns an empty tree */ SearchTree MakeEmpty ( SearchTree T ) { if( T ) { MakeEmpty( T->Left ); MakeEmpty( T->Right ); EmptyList( T->A ); free( T ); } return 0; }/*end MakeEmpty*/
void DataGloveLogger::Preflight() const { bool enabled = ( ( int )OptionalParameter( "LogDataGlove" ) != 0 ); if(enabled) { DataGloveThreadList assigned; AssignGloves(assigned); EmptyList(assigned); // <sigh> } }
// LoadEntry -- Takes an entry and then loads the BBitmap and entry_ref // // YOU MUST DELETE THE BEntry // void PictureViewer::LoadEntry( BEntry* e ) { if ( e == NULL ) return; Window()->Lock(); EmptyList(); theRef = new entry_ref; e->GetRef( theRef ); thePic = BTranslationUtils::GetBitmap(theRef); if ( setup->ViewingMode() == PEEK_IMAGE_WINDOW_TO_IMAGE ) ResizeToImage(); Window()->Unlock(); Refresh(); }
void AllChildsDetachNode(Node *theNode){ Node *oneNode; if (theNode == NULL) return; oneNode = StartLoop(theNode->nodeChilds); while(oneNode) { oneNode->parent = NULL; oneNode = GetNext(theNode->nodeChilds); } EmptyList(theNode->nodeChilds); nodePropagateBBRoot(theNode); }
void packReset( void ) { int n; EmptyList( &pack ); for( n = 0; n < 15; n++ ) { used_n_row[n] = FALSE; } for( n = 0; n < 75; n++ ) { shared_nums[n] = 0; multi_nums[n] = 0; } for( n = 0; n < 25; n++ ) { same_spot[n] = 0; } //lprintf( "pack reset -----------" ); }
void ErrorWindow::RefreshList(void) { EmptyList(); fErrors.Rewind(); error_msg* item = fErrors.GetNextItem(); int32 counter = 0; while (item != NULL) { ErrMsgToItem(item); if (counter % 5 == 0) UpdateIfNeeded(); counter++; item = fErrors.GetNextItem(); } }
void DataGloveLogger::Publish() { char definition[32]; m_enabled = ( ( int )OptionalParameter( "LogDataGlove" ) != 0 ); if( !m_enabled ) return; OpenInterface(); int nGloves = CountGloves(); // needed in order to know how many states to declare. string h; if(nGloves == 1) { // if 1 glove is connected, since we have this info, helpfully set the "default" value of DataGloveHandedness to the correct value DataGloveThreadList g; GetGloves(g); h = ((g.back()->GetHandedness() == FD_HAND_LEFT) ? "L" : "R"); EmptyList(g); } for(int iGlove = 0; iGlove < nGloves; iGlove++) { if(nGloves > 1) h = ((iGlove%2)?" L ":" R ") + h; // If an even number of gloves is attached, the helpful default will end up as L R L R... If an odd number of gloves > 1 is attached, it will end up as R L R .... for(int iSensor = 0; iSensor < MAX_SENSORS; iSensor++) { sprintf(definition, "Glove%dSensor%02d %d 0 0 0", iGlove+1, iSensor+1, SENSOR_PRECISION); BEGIN_EVENT_DEFINITIONS definition, END_EVENT_DEFINITIONS } } sprintf(definition, "%d", nGloves); h = "Source:Log%20Input list DataGloveHandedness= " + (definition+h) + " // DataGlove handedness: L or R for each glove"; BEGIN_PARAMETER_DEFINITIONS "Source:Log%20Input int DataGloveDerivative= 0 0 0 1 // measure changes in glove signals?: 0: no - measure position, 1:yes - measure velocity (enumeration)", "Source:Log%20Input int LogDataGlove= 0 0 0 1 // record DataGlove to states (boolean)", h.c_str(), // "Source:Log%20Input list DataGloveHandedness= 1 L R % % // DataGlove handedness: L or R for each glove", END_PARAMETER_DEFINITIONS }
void ErrorWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_RUN_PROJECT: case M_RUN_IN_TERMINAL: case M_RUN_IN_DEBUGGER: case M_RUN_WITH_ARGS: case M_MAKE_PROJECT: case M_FORCE_REBUILD: { fParent->PostMessage(message); break; } case M_TOGGLE_ERRORS: case M_TOGGLE_WARNINGS: { RefreshList(); break; } case M_COPY_ERRORS: { CopyList(); break; } case M_CLEAR_ERROR_LIST: { EmptyList(); fErrors.msglist.MakeEmpty(); break; } case M_BUILD_WARNINGS: case M_BUILD_FAILURE: { ErrorList list; list.Unflatten(*message); AppendToList(list); break; } case M_JUMP_TO_MSG: { int32 selection = fErrorList->CurrentSelection(); if (selection >= 0) { ErrorItem* item = (ErrorItem*)fErrorList->ItemAt(selection); error_msg* gcc = item->GetMessage(); if (gcc->path.Length() < 1) break; entry_ref ref; BEntry entry(gcc->path.String()); entry.GetRef(&ref); message->what = EDIT_OPEN_FILE; message->AddRef("refs", &ref); if (gcc->line > 0) message->AddInt32("line", gcc->line); be_app->PostMessage(message); } break; } default: BWindow::MessageReceived(message); } }
~CAliasEntry() { EmptyList();}
DataGloveLogger::~DataGloveLogger() { EmptyList(mGloves); }
int HeuristicLimitedSearchMin(SearchBoard *board,Player player,int HMaxZero,const int Level, int Alpha, int Beta, int n, clock_t AcumulatedTime) { bool FoundOnHash; int HashLevel; int HashHeuristic; clock_t Defasagem = AcumulatedTime - clock(); //printf("\nfuncionou ate aqui min\n"); if(n>nivelmax) nivelmax = n; int HMaxLimit = HMaxZero - Level; int HMinLimit = -HMaxZero - Level; numchamadas++; SearchList Greedy; PossibleMovesListMin(board, player,&Greedy); SearchList NextLevel = NewEmptyListMin(); SearchMove M;// = DequeueList(&Greedy); SearchBoard NewBoard; enum piece backup; int LastHeuristic = getHeuristic(board,player); //if(IsEmpty(&Greedy)) //{printf("\n<<<<<<<<<<<<<<<<<<<<<<BUGOU MUITO BIZARRO>>>>>>>>>>>>>>>>>>>>>\n");printBoard(board->board);} while((!IsEmpty(&Greedy))/*&&(-M.hmax-n>HMinLimit)*/) { if(clock()-Tzero>TimeMax) { printf("\nacabou o tempo: %d\n",clock()-Tzero); TimeInterruptionLastSearch = true; return -1000; } numjogadas++; M = DequeueList(&Greedy); NewBoard = *board; if(mkCmpMove(&NewBoard,player,M.Move)!=invalid) { FoundOnHash = false; /*if(getHashValue(&NewBoard, (Player)ChangePlayer(player), &HashHeuristic, &HashLevel)) { if(HashLevel>1+Level-n) { M.h_max = HashHeuristic; FoundOnHash = true; printf("\n%d", HashLevel); } }*/ //if((n<=NIVEL_MAX)&&(-M.h_max-n>HMaxLimit||-M.h_max!=LastHeuristic)) if(!FoundOnHash&&/*n<=NIVEL_MAX&&*/(n<Level||(M.h_max!=LastHeuristic)&&(n<Level+2))) { M.h_max = HeuristicLimitedSearchMax(&NewBoard, (Player)ChangePlayer(player), HMaxZero, Level, Alpha, Beta, n+1, Defasagem+clock()); if(TimeInterruptionLastSearch) return -1000; //addToHash(&NewBoard, (Player)ChangePlayer(player), M.h_max, 1+Level-n); //if(n==Ntest) printf("\nmin%d:%d",n,M.h_max); } //else printf("\n%d\n",n); //undoMov(board->board,M.Move,backup); EnqueueList(&NextLevel,M); // AlphaBeta condition // Alpha is the value of the best alternative for MAX along the path to board // Beta is the value of the best alternative for MIN along the path to board if(M.h_max<Alpha) { EmptyList(&Greedy); EmptyList(&NextLevel); return M.h_max; } if(M.h_max<Beta) Beta = M.h_max; } //M = DequeueList(&Greedy); } move Mov1,Mov2; int resp1 = REAL_MAX, resp2 = REAL_MAX; OrdenateList(&Greedy); OrdenateList(&NextLevel); if(IsEmpty(&Greedy )&&IsEmpty(&NextLevel)) { //printf("BIZU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",n); return REAL_MAX-n; } if(!IsEmpty(&Greedy )) resp1 = DequeueList(&Greedy).h_max; if(!IsEmpty(&NextLevel)) resp2 = DequeueList(&NextLevel).h_max; //while(!IsEmpty(&Greedy)) printf("\n%d:%d",n,DequeueList(&Greedy).h_max); //while(!IsEmpty(&NextLevel)) printf("\n%d:%d",n,DequeueList(&NextLevel).h_max); //printf("\n%d:final: %d",n,(resp1<resp2?resp1:resp2)); //if(resp1==resp2&&resp1==REAL_MAX&&IsEmpty(&Greedy )&&IsEmpty(&NextLevel)) return REAL_MAX-10;//printf("MIN%dBUGOU BIZARRO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",n); EmptyList(&Greedy); EmptyList(&NextLevel); //if(n==Ntest) printf("\nMIN%d:%d",n,(resp1<resp2?resp1:resp2)); return (resp1<resp2?resp1:resp2); }
move IterativeMinMax(SearchBoard *board, Player player, int time_max) { char name[6]; int TIME_INCREASE = 1; SearchList Greedy = NewEmptyListMax(); SearchList NextLevel; if(player==whites) PossibleMovesListMax(board, player, &NextLevel); else PossibleMovesListMin(board, player, &NextLevel); SearchMove M; SearchBoard NewBoard; enum piece backup; int HMaxLimit = getHeuristic(board, player); int Alpha = REAL_MIN; int Beta = REAL_MAX; int ContadorDoNumerodeJogadasPossiveis=0; Tzero = clock(); clock_t SpentTime = 1;// para nao ter 0 no denominador TimeMax = time_max*CLOCKS_PER_SEC; TimeInterruptionLastSearch = false; clock_t AcumulatedTime; int auxiliar; for(int i=2; clock()-Tzero<time_max && !TimeInterruptionLastSearch /*&& i<=NIVEL_MIN*/; i++) { //NIVEL_MAX = i; Alpha = REAL_MIN; Beta = REAL_MAX; OrdenateList(&NextLevel); AtributeList(&Greedy,&NextLevel); EmptyList(&NextLevel); //M = DequeueList(&Greedy); ContadorDoNumerodeJogadasPossiveis = 0; while(!TimeInterruptionLastSearch&&clock()-Tzero<time_max&&!IsEmpty(&Greedy)) { M = DequeueList(&Greedy); movToStr(M.Move,name); //printf("\n%s:",name); NewBoard = *board; if(mkCmpMove(&NewBoard,player,M.Move)!=invalid) { ContadorDoNumerodeJogadasPossiveis++; movToStr(M.Move,name); printf("\n%d : ",i); printf("%s: %d",name,M.h_max); AcumulatedTime = clock(); if(player==whites) auxiliar = HeuristicLimitedSearchMin(&NewBoard,(Player)ChangePlayer(player),HMaxLimit,i,Alpha,Beta,1,AcumulatedTime); else auxiliar = HeuristicLimitedSearchMax(&NewBoard,(Player)ChangePlayer(player),HMaxLimit,i,Alpha,Beta,1,AcumulatedTime); if(!TimeInterruptionLastSearch) { M.h_max = auxiliar; } printf(" : %d\n",M.h_max); //printf("%d",M.h_max); EnqueueList(&NextLevel,M); } else { //printf("\nfail"); } //M = DequeueList(&Greedy); } if(ContadorDoNumerodeJogadasPossiveis==1) return DequeueList(&NextLevel).Move; //TIME_INCREASE = (time(NULL)-Tzero)/SpentTime; //SpentTime = time(NULL)-Tzero; } ConcatenateList(&Greedy,&NextLevel); OrdenateList(&Greedy); SearchMove resp, aux; resp = DequeueList(&Greedy); NewBoard = *board; mkCmpMove(&NewBoard,player,aux.Move); int contador; srand(time(NULL)); SearchBoard AnotherNewBoard; while(!IsEmpty(&Greedy)) { aux = DequeueList(&Greedy); AnotherNewBoard = *board; mkCmpMove(&AnotherNewBoard,player,aux.Move); if((player==whites&&aux.h_max>resp.h_max)||(player==blacks&&aux.h_max<resp.h_max)) { resp = aux; NewBoard = *board; mkCmpMove(&NewBoard,player,aux.Move); } if(aux.h_max==resp.h_max) { AnotherNewBoard = *board; mkCmpMove(&AnotherNewBoard,player,aux.Move); if((player==whites&&get_heuristics(&AnotherNewBoard,player)>get_heuristics(&NewBoard,player)) ||(player==blacks&&get_heuristics(&AnotherNewBoard,player)<get_heuristics(&NewBoard,player)) ||rand()%50==0) { resp = aux; NewBoard = AnotherNewBoard; } } } return resp.Move; }
void CustomerList::RemoveCustomer(Customer &someCustomer) { Node<Customer> * traversePtr; Node<Customer> * actionPtr; if(isEmpty()) { // cout << "Can't Dequeue an empty list" << endl; throw EmptyList(); } traversePtr = _head; int index = 0; while (index < _listLimit && traversePtr != NULL && !(traversePtr->GetData() == someCustomer)) { traversePtr = traversePtr->GetNext(); index++; } // overloaded operator if (traversePtr->GetData() == someCustomer) { // head deletion if (traversePtr == _head) { Dequeue(); } // end deletion else if (traversePtr == _tail) { _tail = _tail->GetPrevious(); _tail->SetNext(NULL); // _tail->_next = NULL; traversePtr->Orphan(); delete traversePtr; //Decrements the _nodeCount DecrementCount(); } // middle deletion else { actionPtr = traversePtr->GetPrevious(); actionPtr->SetNext(traversePtr->GetNext()); traversePtr->SetNext(traversePtr->GetNext()); traversePtr->SetPrevious(actionPtr); traversePtr->Orphan(); delete traversePtr; //Decrements the _nodeCount DecrementCount(); } } if (index == _listLimit && traversePtr == NULL) { // throw exception class if not found. traversePtr = NULL; throw NotFound(); } }
CMyList::~CMyList() { EmptyList(); pthread_spin_destroy(&m_MyListLocker); }
IE::point PathFinder::_GeneratePath(const IE::point& start, const IE::point& end) { fPoints.clear(); IE::point maxReachableDirectly = start;//_CreateDirectPath(start, end); if (PointSufficientlyClose(maxReachableDirectly, end) || !_IsPassable(end)) return maxReachableDirectly; std::list<point_node*> openList; std::list<point_node*> closedList; point_node* currentNode = new point_node(maxReachableDirectly, NULL, 0); openList.push_back(currentNode); uint32 tries = 4000; bool notFound = false; for (;;) { // If adiacent nodes are passable, add them to the list _AddIfPassable(offset_point(currentNode->point, fStep, 0), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, fStep, fStep), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, 0, fStep), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, -fStep, fStep), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, -fStep, 0), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, -fStep, -fStep), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, fStep, -fStep), *currentNode, openList, closedList); _AddIfPassable(offset_point(currentNode->point, 0, -fStep), *currentNode, openList, closedList); openList.remove(currentNode); closedList.push_back(currentNode); if (PointSufficientlyClose(currentNode->point, end)) break; currentNode = _GetCheapestNode(openList, end); if (currentNode == NULL || --tries == 0) { notFound = true; break; } } //std::list<point_node*>::const_iterator i; if (notFound) { // TODO: Destination is unreachable. // Try to find a reachable point near destination std::cout << "Path not found" << std::endl; EmptyList(closedList); EmptyList(openList); return start; } EmptyList(openList); std::list<point_node*>::reverse_iterator r = closedList.rbegin(); point_node* walkNode = *r; for (;;) { //fPoints.insert(directRouteEnd, walkNode->point); //directRouteEnd--; fPoints.push_front(walkNode->point); const point_node* parent = walkNode->parent; if (parent == NULL) break; walkNode = const_cast<point_node*>(parent); } EmptyList(closedList); assert (PointSufficientlyClose(fPoints.back(), end)); return fPoints.back(); }
SLS_SimpleList :: ~SLS_SimpleList( ) { EmptyList( ) ; } // End of function: SLS !List destructor