// erase bombs and diamonds when off screen. void handleBombsAndDiamonds(XInfo &xInfo) { for (int i = 0; i < (int)dBombList.size(); i++) { if (dBombList[i]->getX() < -20 || (dBombList[i]->getSpeedY() > 0 && dBombList[i]->getY() > xInfo.height + 20) || (dBombList[i]->getSpeedY() < 0 && dBombList[i]->getY() < -20)){ delete dBombList[i]; dBombList.erase(dBombList.begin() + i); } } for (int i = 0; i < (int)dDiamondList.size(); i++) { if (dDiamondList[i]->getX() < -20 || dDiamondList[i]->getY() > xInfo.height){ delete dDiamondList[i]; dDiamondList.erase(dDiamondList.begin() + i); } } }
void DeleteVip() { cin.get(); size_t i; string studentId; cout << endl; cout << "********************************************************" <<endl; cout << "* Delete vip by number... *" <<endl; cout << "********************************************************" <<endl; cout << "Please input student Id(string): "; cin >> studentId; for(i = 0; i < vip.size(); i++) { pVip = vip[i]; if(0 == studentId.compare(pVip->GetStudentId())) { cout << endl; pVip->DisplayInfo(); pVip->DisplayOtherInfo(); pVip = 0; vip.erase(vip.begin() + i); cout << "********************************************************" <<endl; cout << "* Finished to delete... *" <<endl; cout << "********************************************************" <<endl; return; } } cout << "********************************************************" <<endl; cout << "* Can't find vip... *" <<endl; cout << "********************************************************" <<endl; }
bool Huffman::Solve(){ while(tree.size()>=digitNum){ sort(tree.begin(),tree.end(),NodeCompare); Node* combine=new Node; combine->value=CHAR_MAX; combine->frequency=0; combine->child=tree.front(); combine->sibling=NULL; for(int i=0;i<digitNum;i++){ if(combine->value>tree[i]->value) combine->value=tree[i]->value; combine->frequency+=tree[i]->frequency; if(i+1<digitNum) tree[i]->sibling=tree[i+1]; } tree.erase(tree.begin(),tree.begin()+digitNum); tree.push_front(combine); } Coding(tree.front(),""); double average=0.0; for(int i=0;i<letterNum;i++) average+=letter[i]->frequency*letter[i]->code.length(); average/=tree.front()->frequency; printf("Set %d; average length %.2lf\n",ID,average); for(i=0;i<letterNum;i++) printf(" %c: %s\n",letter[i]->value,letter[i]->code.c_str()); printf("\n"); return true; }
int PickFilesToLoad(deque<string>& files) { files = extrautility::ListFiles(WALLPAPER_DIR); if(extrautility::GetLastError() == extrautility::BAD_DIRECTORY) { ERROR_SYSTEM("The ~/.wallpapers/ directory does not exist." " Please create and populate it."); return -1; } //Inverse the set of all files with the following extensions and filter them //out. extrautility::RegexFilter filter(".+\\.jpg|.+\\.jpeg|.+\\.tiff|.+\\.gif|.+\\.bmp|.+\\.png"); filter.invert(); files.erase(std::remove_if(files.begin(), files.end(), filter), files.end()); if(files.empty()) { ERROR_SYSTEM("The ~/.wallpapers/ directory is empty."); return -1; } std::shuffle(files.begin(), files.end(), std::default_random_engine()); return 0; }
virtual void AddPacket(shared_ptr<const vector<BYTE>> data, DWORD timestamp, DWORD pts, PacketType type) override { packets.emplace_back(make_shared<const packet_t>(type, timestamp, pts, data)); if (start_recording) { start_recording = false; CreateRecordingHelper(App->fileStream, packets); } if ((*data)[0] != 0x17) return; HandleSaveTimes(pts); keyframes.emplace_back(timestamp, --end(packets)); while (keyframes.size() > 2) { if (((long long)timestamp - keyframes[0].first) < (seconds * 1000) || ((long long)timestamp - keyframes[1].first) < (seconds * 1000)) break; packets.erase(begin(packets), keyframes[1].second); keyframes.erase(begin(keyframes)); } }
void mythread_exit() { tcb *this_th = thread_list[this_th_th]; while (!this_th->waiting.empty()) { queue.push_back(this_th->waiting.front()); this_th->waiting.pop_front(); } deque<tcb*>::iterator it = find(queue.begin(), queue.end(), this_th); if (it != queue.end()) queue.erase(it, it+1); if (queue.empty()) { exit(0); // no other thread remaining } // run the next thread if availiable tcb * thread = queue.front(); queue.pop_front(); tcb *th = thread_list[this_th_th]; delete th; thread_list.erase(this_th_th); this_th_th = thread->id; setcontext(&(thread->context)); }
// LOGIC: if there's still stuff on the queue, // we pop one vertex*, then check it to see if it's the destination // if yes, we are done (return true) // if no, we push all its unvisited neighbor vertex* on the queue // for each neighbor, we store a pointer to the vertex* we came from // and then return the result of breadth first search again. // If the queue is empty, we give up (return false) bool graph::breadth_first_search(vertex* u, map<vertex*, bool>& visited, deque<vertex*>& yet_to_explore, map<vertex*, vertex*>& path) { if (!yet_to_explore.empty()) { //grab the last item in the deque vertex* b = yet_to_explore.front(); //grab first entry use .front() //pop this item off yet_to_explore.erase(yet_to_explore.begin()); //if that item is u, were' done (our base case) if(b->get_city_name() == u-> get_city_name()) { return true; } vector<vertex*>::iterator it; for(it = edges[b].begin(); it != edges[b].end(); ++it) { vertex* neighbor = *it; if(visited[neighbor] == false) { yet_to_explore.push_back(neighbor); visited[neighbor] = true; path[neighbor] = b; // we came from w to get to neighbor } } return depth_first_search(u, visited, yet_to_explore, path); } else return false; }
//write bit stream to file void str2bin(deque<char> & ss,ofstream & of) { while(ss.size()>0) { of<<bin2ascii(&ss[0]); ss.erase(ss.begin(),ss.begin()+8); } }
void updateCache(Node* node) { if (node == NULL) return; auto iter = find(queue.begin(), queue.end(), node); if (iter == queue.end() || iter == queue.end() - 1) return; queue.erase(iter); queue.push_back(node); }
void assign(int cur) { D.push_back(cur); ++res; if(D.front()<=cur-K) D.pop_front(); if(SZ(D)>K/2) { for(int i=SZ(D)-1; i>=0; --i) if(is.count(D[i])==0) { D.erase(D.begin()+i); --res; break; } } }
void moveToFront(int i, Xpp* xpp, Draw* draw) { xpp->resizeAndCenter(windows.front(), minW, minH); windows.push_front (windows[i]); windows.erase (windows.begin()+i+1); xpp->raise (windows.front()); xpp->focus (windows.front()); isBig = false; draw->move (windows.front(), 0); draw->update (); }
void sub(Node &o){ deque<string>::iterator it; while(!o.dq.empty()){ it = find(dq.begin(), dq.end(), o.dq.front()); if (it!=dq.end()){ dq.erase(it); } o.dq.pop_front(); } }
void ofURLFileLoaderImpl::remove(int id){ Poco::ScopedLock<ofMutex> lock(mutex); for(int i=0;i<(int)requests.size();i++){ if(requests[i].getID()==id){ requests.erase(requests.begin()+i); return; } } ofLogError("ofURLFileLoader") << "remove(): request " << id << " not found"; }
int HexGame::MontoCarloAI(Color color) { // TODO Auto-generated constructor stub cout<<"computer is thinking..."<<endl; int pMax,nWinsMax=0; Color oppCol; if(color==Color::RED) oppCol=Color::BLUE; else oppCol=Color::RED; for(auto position:unoccupied){ // unsorted unoccupied int nwins=0; Graph cfgG=*G; //make a copy to current configuration if(cfgG.get_node_value(position)==Color::WHITE) cfgG.set_node_value(position,color); else cout<<"something wrong on unoccupied"<<endl; auto cfgUnoccupied=unoccupied; auto iter=find(cfgUnoccupied.begin(),cfgUnoccupied.end(),position); cfgUnoccupied.erase(iter);// removes the element in position if(winMC(color,cfgG)){ pMax=position; break; // if wins } for(int i=0;i<MonteCarloTrials;i++){ // for all monte carlo trials Graph cpG=cfgG; //make a copy auto cpUnoccupied=cfgUnoccupied; random_shuffle(cpUnoccupied.begin(), cpUnoccupied.end()); // generate a random series while(!cpUnoccupied.empty()){ // it's opponent's turn int pos=cpUnoccupied.front(); cpUnoccupied.pop_front(); //removes the first element if(cpG.get_node_value(pos)==Color::WHITE) cpG.set_node_value(pos,oppCol); else { cout<<"pos is "<<pos<<" something wrong with unoccupied in oppCol"<<endl; cout<<( (cpG.get_node_value(pos)==Color::BLUE)?"BLUE":"RED" )<<endl; cout<<"oppCol is "<<( (oppCol==Color::BLUE)?"BLUE":"RED" )<<endl; } if(!cpUnoccupied.empty()){ pos=cpUnoccupied.front(); cpUnoccupied.pop_front(); //removes the first element if((cpG.get_node_value(pos)==Color::WHITE) )cpG.set_node_value(pos,color); } } if(winMC(color,cpG))nwins++; // after fill up the board } // end of one trial if(nwins>nWinsMax){ nWinsMax=nwins; pMax=position; } } // for each next possible move auto iter=find(unoccupied.begin(),unoccupied.end(),pMax); unoccupied.erase(iter); // remove the occupied one G->set_node_value(pMax,color); drawBoard(); return pMax; }
void completeJob(string jobID) { deque<JobStory>::iterator it; for(it = runningJobSet.begin(); it != runningJobSet.end(); it++) { if(it->jobID == jobID) break; } assert(it != runningJobSet.end()); completedJobSet.push_back(*it); runningJobSet.erase(it); }
virtual ~PhysicalObject() { for (long i = 0; i < objects.size(); i++) { if (objects[i] == this) { objects.erase(objects.begin() + i); break; } } }
void ReferencePage( deque<int>& Q, unordered_map<int,deque<int>::iterator>& M, int p ) { // if p is not in M, add p to both Q and M if( M.count(p)==0 ) { Enqueue(Q,p); M[p] = Q.begin(); } else { deque<int>::iterator it = M[p]; Q.erase(it); Enqueue(Q,p); } }
void permute(string &s,int n,int k,deque<int> &DQ){ if(DQ.size()==0) return; auto it=DQ.begin(); while(fact[n-1]<k){ k-=fact[n-1]; it++; } s.append(to_string(*it)); DQ.erase(it); permute(s,n-1,k,DQ); }
void GameLogic() { static int cnt = 0 ; float dt = (float)time_interval * 0.001 ; current_time = glutGet( GLUT_ELAPSED_TIME ) ; //update particles for( size_t i = 0 ; i < particles.size() ; ++i ) { //update position Particle& p = particles[i] ; p.pos += dt * p.vel ; p.vel += dt * gravity ; //update intensity p.intensity = std::max( 0.0f, (max_life - LifeTime(p))/max_life ) ; //update trail if( cnt > 5 ) { p.trail.push_back( p.pos ) ; } if( p.trail.size() > max_trail ) { p.trail.pop_front() ; } //kick old particle if( LifeTime(p) > max_life ) { particles.erase( particles.begin()+i ) ; } //explode if( p.exploded == false && p.vel[1] < 0.5 ) { Explode(p) ; particles.erase( particles.begin()+i ) ; //father died } } cnt > 5? cnt=0 : cnt++ ; }
bool FindStrInDeque(deque<string> &sdeq, string str) { deque<string>::iterator it = find(sdeq.begin(), sdeq.end(), str); if (it == sdeq.end()) { return false; } else { sdeq.erase(it); return true; } }
/** * converse of printing tree */ void read(node*cur,deque<char> & ss) { char aux=ss.front(); ss.erase(ss.begin()); if(aux=='1' ) { string tmp(ss.begin(),ss.begin()+8); cur->ASCII=bin2ascii(&tmp[0]); ss.erase(ss.begin(),ss.begin()+8); } else { cur->left=new node(0,0,0,0); cur->right=new node(0,0,0,0); if(cur->left==0||cur->right==0){ cout<<"memory allocation error!"<<endl; exit(1);} cur->left->code.append(cur->code); cur->left->code.append("0"); cur->right->code.append(cur->code); cur->right->code.append("1"); read(cur->left,ss); read(cur->right,ss); } }
/* * decode bit stream to bytes. * recursively traverse tree until leaf. */ void read(node*cur,deque<char> & ss,ofstream&of) { if(cur->left==0 ) { of<<cur->ASCII; } else { char aux=ss.front(); ss.erase(ss.begin()); if(aux=='0') read(cur->left,ss,of); else read(cur->right,ss,of); } }
bool removeName(int index) { bool acted = false; int at = 0; for (deque<Entry>::iterator it=q.begin(); it!=q.end(); it++) { string nname = (*it).name; if (at==index) { acted = true; q.erase(it); // iterators are now invalid break; } at++; } return acted; }
// printing the path.. from back to front void print_path(deque<node>& dq) { node nd = dq.back(); while (nd._c != 0 || nd._r != 0) { printf("Row: %d, Col: %d, Val: %d\n", nd._r, nd._c, nd._val); arr2[nd._r][nd._c] = 1; dq.erase(find_if(dq.begin(), dq.end(), [nd](node n){ return n._val == nd._val; }), dq.end()); nd = find_next_node(dq, nd); } printf("Row: %d, Col: %d, Val: %d\n", nd._r, nd._c, nd._val); printf("\n"); }
/* * Disconnection callback, called when a client disconnects */ void discCallback( TSockId from, void *p ) { // Remove all occurences of from in the queue deque<TSockId>::iterator iq; for ( iq=ClientIds.begin(); iq!=ClientIds.end(); ) { if ( *iq == from ) { iq = ClientIds.erase( iq ); } else { iq++; } } }
bool removeName(const char *name) { bool acted = false; for (deque<Entry>::iterator it=q.begin(); it!=q.end(); it++) { string nname = (*it).name; if (nname==name) { acted = true; q.erase(it); // iterators are now invalid break; } } if (acted) { // in case there are other copies, remove recursively removeName(name); } return acted; }
void add_paths(deque<path*> &open, deque<path*> &closed, deque<path*> paths) { deque<path*>::iterator i,j; //add neighbors to open list, duplicates included for(i=paths.begin(); i!=paths.end(); i++) { j = find_if(closed.begin(), closed.end(), pathByName(*i)); if (j != closed.end()) continue; //neighbor already in closed, don't add j = find_if(open.begin(), open.end(), pathByName(*i)); if (j != open.end()) { //found duplicate path if ((*i)->cost < (*j)->cost) { //new path is shorter open.erase(j); //erase old path open.push_back(*i); //add new path } else continue; //old path is shorter; don't add new one } else { open.push_back(*i); //neither already closed nor dup, add to open list } } }
bool reduce(deque<double>& nums) { if (nums.size() == 1 && abs(nums.front() - target) < EPS) { return true; } for (int i = 1; i < nums.size(); i++) { for (int j = 0; j < i; j++) { auto num_i = nums[i], num_j = nums[j]; nums.erase(nums.begin() + i); nums.erase(nums.begin() + j); nums.push_back(num_i + num_j); if (reduce(nums)) return true; nums.pop_back(); nums.push_back(num_i * num_j); if (reduce(nums)) return true; nums.pop_back(); nums.push_back(num_i - num_j); if (reduce(nums)) return true; nums.pop_back(); nums.push_back(num_j - num_i); if (reduce(nums)) return true; nums.pop_back(); if (num_i != 0) { nums.push_back(num_j / num_i); if (reduce(nums)) return true; nums.pop_back(); } if (num_j != 0) { nums.push_back(num_i / num_j); if (reduce(nums)) return true; nums.pop_back(); } nums.insert(nums.begin() + j, num_j); nums.insert(nums.begin() + i, num_i); } } return false; }
int HexGame::move(Color color){ int x,row,col; char dot; do { cin.clear(); cin.sync(); cout<<"please input the row and columnnumber (0-"<<N-1<<") ,the format is nRow,nCol "<<endl; cin>>row>>dot>>col; x=row*N+col; if(row>=0 && row<N && col>=0 && col<N && G->get_node_value(x)==Color::WHITE){ G->set_node_value(x,color); drawBoard(); auto iter=find(unoccupied.begin(),unoccupied.end(),x); unoccupied.erase(iter); // remove the occupied one break; } }while(1); return x; // return the move position }
virtual void AddPacket(BYTE *data, UINT size, DWORD timestamp, DWORD pts, PacketType type) override { packets.emplace_back(make_shared<packet_t>(type, timestamp, pts, vector<BYTE>(data, data + size))); if (data[0] != 0x17) return; HandleSaveTimes(pts); keyframes.emplace_back(timestamp, --end(packets)); while (keyframes.size() > 2) { if (((long long)timestamp - keyframes[0].first) < (seconds * 1000) || ((long long)timestamp - keyframes[1].first) < (seconds * 1000)) break; packets.erase(begin(packets), keyframes[1].second); keyframes.erase(begin(keyframes)); } }