Example #1
0
void DFSVisit(vector < vector < TNode* > > &g, size_t s, int &time, list <TNode *> &sorts)
{
	g[s][0]->clr = GREY;
	g[s][0]->open = ++time;
	for (size_t i = 1; i < g[s].size(); ++i)
	{
		if (g[s][i]->clr == WHITE)
		{
			g[s][i]->parent = g[s][0];
			DFSVisit(g, g[s][i]->n, time, sorts);
		}
	}
	g[s][0]->clr = BLACK;
	sorts.push_front(g[s][0]);
	g[s][0]->close = ++time;
}
Example #2
0
 void put(int key, int value) {
     auto it = data.find(key);
     if (it != data.end()) {
         access_order.splice(access_order.begin(), access_order, it->second.second);
         data[key] = {value, access_order.begin()};
     } else {
         if (current_capacity == _capacity) {
             data.erase(*access_order.rbegin());
             access_order.pop_back();
         } else {
             current_capacity++;
         }
         access_order.push_front(key);
         data[key] = {value, access_order.begin()};
     }
 }
Example #3
0
void RTF ()
{	
	list<int>::iterator u = l.begin();
	while (u != l.end())
	{
		int old_height = h[*u];
		DISCHARGE(*u);
		if (h[*u] != old_height)
		{
			l.push_front(*u);
			l.erase(u);
			u = l.begin();
		}
		++u;
	}
}
Example #4
0
/**
* Apends all of the valid moves in the down-right 
* direction to mvoes list
*/
void Piece::getDownRightSquares(list<square>& moves){
	int temp_row=row+1;
	int temp_col=col+1;
	while(temp_row<=7 && temp_col<=7){
		if(isPossibleMove(temp_row,temp_col)){
			moves.push_front((square){temp_row,temp_col});
			if(board->canDestroy(temp_row,temp_col)){
				break;
			}
		}else{
			break;
		}
		temp_row+=1;
		temp_col+=1;
	}
}
Example #5
0
void LoaderQueue::touch(Cache::ItemPtr const & item)
{
	if (! cache_set_.insert(item).second) {
		list<Cache::ItemPtr>::iterator
			it = cache_queue_.begin();
		list<Cache::ItemPtr>::iterator
			end = cache_queue_.end();

		it = find(it, end, item);
		if (it != end)
			cache_queue_.erase(it);
	}
	cache_queue_.push_front(item);
	if (!running_)
		startLoader();
}
Example #6
0
 void lru_add(const K& key, const VPtr& val, list<VPtr> *to_release)
 {
     typename ceph::unordered_map<K, typename list<pair<K, VPtr> >::iterator, H>::iterator i =
         contents.find(key);
     if (i != contents.end())
     {
         lru.splice(lru.begin(), lru, i->second);
     }
     else
     {
         ++size;
         lru.push_front(make_pair(key, val));
         contents[key] = lru.begin();
         trim_cache(to_release);
     }
 }
UINT1 BaseNetworkMgr::targetNetwork_Bystatus(const UINT1    p_status,list<Base_Network *> & p_networks)
{
        list<Base_Network *>::iterator itor;
        lock_Mutex();
        itor = networks.begin();
        while (itor != networks.end())
        {
                if ((*itor)->get_status() == p_status)
                {
                        p_networks.push_front(*itor);
                }
                itor++;
        }
        unlock_Mutex();
        return RETURN_OK;
}
Example #8
0
void add_unique(list<dynamic_bitset<> >& masks,const list<dynamic_bitset<> >& old_masks,
		const dynamic_bitset<>& mask) 
{
    // don't add the mask unless contains internal partitions (it could be all 0)
    if (mask.count() < 4) return;

    // don't add the mask if we already have that mask
    for(const auto& m: old_masks)
	if (m == mask) return;

    for(const auto& m: masks)
	if (m == mask) return;

    // otherwise, add the mask
    masks.push_front(mask);
}
Example #9
0
//return false if not a dag
bool graph::topologicalSortRec(node *n, list<node *> &l_sorted)
{
    if(n->b_tempMark) //flemme to do accessors
        return false; //if it is marked temporarly then it was also a n in a upper call of traverse, there fore we hav a cycle

    if(!n->isMarkedNode())
    {
        n->b_tempMark=true;
        for(node *m:n->l_successors)
            this->topologicalSortRec(m,l_sorted); //for each child of n we call recursivly
        n->markNode(); //we mark the node n because all operation are finished with him
        n->b_tempMark=false; //
        l_sorted.push_front(n); //we add n to the list of sorted node
    }
    return true;
}
UINT1 BaseNetworkMgr::targetNetwork_Bytenant_ID(const string   p_tenant_ID,list<Base_Network *> & p_networks)
{
        list<Base_Network *>::iterator itor;
        lock_Mutex();
        itor = networks.begin();
        while (itor != networks.end())
        {
                if ((*itor)->get_tenant_ID() == p_tenant_ID)
                {
                        p_networks.push_front(*itor);
                }
                itor++;
        }
        unlock_Mutex();
        return RETURN_OK;
}
Example #11
0
void inventory::order (int wid)
{
    cout << "Received order for widget type " << wid << endl;
    list<Widget,allocator<void> >::iterator wehave = find_if(on_hand.begin(), on_hand.end(), 
                                            bind2nd(WidgetTester(), wid));
    if (wehave != on_hand.end())
    {
        cout << "Ship " << *wehave << endl;
        on_hand.erase(wehave);
    }
    else
    {
        cout << "Back order widget of type "  << wid  << endl;
        on_order.push_front(wid);
    }
}
Example #12
0
// 读取发送失败文件
void SocketSender::readFailFile (
	list<MLogRec>& logs) throw (ReadException) {
	cout << "读取发送失败文件开始..." << endl;
	ifstream ifs (m_failFile.c_str (),
		ios::binary);
	if (! ifs)
		throw ReadException ();
	MLogRec log;
	while (ifs.read ((char*)&log, sizeof (log)))
		logs.push_front (log);
	if (! ifs.eof ())
		throw ReadException ();
	ifs.close ();
	unlink (m_failFile.c_str ());
	cout << "读取发送失败文件完成。" << endl;
}
int main(int argc, char *argv[])
{
    pair <int, int> tmp;
    bool first;
    while (~scanf("%d%d", &n, &m)) {
        if (!n && !m)
            break;
        memset(arr, 0, sizeof(arr));
        first = true;
        for (int i = 0; i < m; i++) {
            scanf("%d%d", &tmp.first, &tmp.second);
            arr[tmp.second]++;
            List.push_front(tmp);
        }
        List.sort(cmp);
        while(!List.empty()) {
            for (int i = 1; i <= n; i++) {
                if (arr[i]==0) {
                    if(!first)
                        putchar(32);
                    else {
                        first = false;
                    }
                    arr[i] = -1;
                    printf("%d", i);
                }
            }
            do {
                tmp = List.front(); List.pop_front();
                arr[tmp.second]--;
            }while(tmp.first == List.front().first);
        }
            for (int i = 1; i <= n; i++) {
                if (arr[i]==0) {
                    if(!first)
                        putchar(32);
                    else {
                        first = false;
                    }
                    arr[i] = -1;
                    printf("%d", i);
                }
            }
        putchar(10);
    }
    return 0;
}
Example #14
0
 void set(int key, int value) {
     if (dict.find(key) != dict.end())
     {
         data.splice(data.begin(), data, dict[key]);
         dict[key]->val = value;
     }    
     else 
     {
         if (data.size() == capacity)
         {
             dict.erase(data.back().key);
             data.pop_back();
         }
         data.push_front(Node(key, value));
     }
     dict[key] = data.begin();
 }
Example #15
0
/**
* Apends all of the valid moves in the up-left 
* direction to mvoes list
*/
void Piece::getUpLeftSquares(list<square>& moves){
	int temp_row=row-1;
	int temp_col=col-1;
	while(temp_row>=0 && temp_col>=0){
		//std::cout << "getUpLeftSquares temp_row:" << temp_row << std::endl;
		if(isPossibleMove(temp_row,temp_col) ){
			moves.push_front((square){temp_row,temp_col});
			if(board->canDestroy(temp_row,temp_col)){
				break;
			}
		}else{
			break;
		}
		temp_row-=1;
		temp_col-=1;
	}
}
Example #16
0
 void set(int key, int value) {
     if (m_map.find(key) == m_map.end()) {
         CacheEntry newItem(key, value);
         if (m_LRU_cache.size() >= m_capacity)
         {
             m_map.erase(m_LRU_cache.back().key);
             m_LRU_cache.pop_back();                
         }
         
         m_LRU_cache.push_front(newItem);
         m_map[key] = m_LRU_cache.begin();
         return;
     }
     
     m_map[key]->value = value;
     MoveToHead(key);
 }
Example #17
0
/*******************************
**(函数名)DisplayFunction:
**(功能用途):回调函数
**(返回值)return:
** (作者)Creator:
** (日期)Date:
**(修改人)Modifier:
**(修改日期)ModifyDate:
**(版本)Version:
*******************************/
void DisplayFunction()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    if( g_dataReady )
    {
        //进行绘制
        DrawWaves();
        //将音频数据存放在list中,方便绘制
        if( g_waveList.size() <= g_depth )
        {
            if( g_waveList.size() == g_depth )
                g_waveList.pop_back();
            g_waveList.push_front( g_audioBuffer );
        }
    }
    glutSwapBuffers();
}
Example #18
0
void add(int *iterator,int *pointer,int cnt,int k)
{
	if(!*iterator){	return;}
	if(sumation(pointer[*iterator],pointer[cnt])=='>')
	{
		if(compare(pointer[*(iterator+1)],pointer[cnt]))
			add(iterator+1,pointer,cnt);
		else
			h.insert(iterator+1,cnt);
	}
	else if(sumation(pointer[*iterator],pointer[cnt],k)=='<')
	{
		if(compare(pointer[cnt],pointer[*iterator],k))
			h.push_front(cnt);
	}

}
Example #19
0
int main() {

	freopen("in.txt", "r", stdin);

	int m, n;

	while (cin >> m >> n) {
		if (m == 0) {
			return 0;
		}

		// Initialize the graph
		location.clear();
		int i, j;
		for (i = 0; i < 105; i++){
			for (j = 0; j < 105; j++) {
				graph[i][j] = '.';
			}
		}

		// Get all the input for the graph
		for (i = 1; i <= m; i++) {
			for (j = 1; j <= n; j++) {
				cin >> graph[i][j];
			}
		}

		// Recursive step
		int result = 0;
		for (i = 1; i <= m; i++) {
			for (j = 1; j <= n; j++) {
				if (graph[i][j] == '@') {
					result++;
					location.push_front(i);
					location.push_front(j);
					while (location.size()) {
						floodFill();
					}
				}
			}
		}

		cout << result << endl;
	}
	return 0;
}
Example #20
0
 void set(int key, int value) {
 	if (m.find(key) != m.end())//如果key已经存在,更新节点的值和顺序即可
 	{
 		l.splice(l.begin(),l,m[key]);
 		m[key] = l.begin();
 		l.begin()->value = value;
 	}
 	else
 	{
 		if (l.size() == this->capacity)//如果key不存在,但是list已经满了
 		{
 			m.erase(l.back().key);//删除key
 			l.pop_back();//list也删除
 		}
 		l.push_front(Node(key,value));
 		m[key] = l.begin();
 	}
 }
Example #21
0
 void set(int key, int value) {
     auto it = kv.find(key);
     if(it != kv.end()){
         touch(key);
         kv[key]->value = value;
     }
     else{
         if(cap == 0){
             kv.erase(lst.back().key);
             lst.pop_back();
         }
         lst.push_front(item(key, value));
         kv[key] = lst.begin();
         if(cap){
             cap--;
         }
     }
 }
Example #22
0
int abMax(int** board, int alpha, int beta, list<Move>& actions, Move move, int depth) {

	switch(terminalState(board, move)) {
	case Draw:
		return 0;
		break;
	case Win:
		return -INFINITE_SCORE;
		break;
	}

	//Depth handling
	if(depth==0)
		return staticEvaluation(board);
	if(depth != -1)
		depth--;

	list<Move>* children = legalMoves(board);

	int v = -INFINITE_SCORE;
	int w;

	for(list<Move>::iterator it = children->begin(); it != children->end(); ++it) {
		list<Move> &tmp = list<Move>();
		int i = it->x;
		int j = it->y;
		doMove(board, *it, PLAYER_COLOR);
		display(board);
		w = abMin(board, alpha, beta, tmp, *it,depth);
		undoMove(board, *it);

		if(w > v) {
			v = w;
			actions = tmp;
			actions.push_front(*it);
		}

		if(v >= beta)
			return v;

		alpha = max(alpha, v);
	}
	return v;
}
int main()
{
    string buf;
    buf.resize(51);
    int bi;
    char line[size];
    char* pline;
    int n;
    while( gets(line) )
	{
	    pline= line;
	    if( *pline=='0' && *(pline+1)==0)
			break;
	    bi = 0;
	    while( *pline )
		{
			if( isalpha(*pline) )		//isalpha=>>Check if character is alphabetic=>>ctype.h
			{
                // find the word
                bi = 0;
                while( *pline &&  isalpha(*pline) ) buf[bi++] = *pline++;
                buf[bi] = 0;
                printf("%s" , buf.c_str() );
                table.push_front( buf );
            }
			else if( *pline >= '0' && *pline <= '9' )		//if number
			{
                // find the number
                n = 0;
                while( *pline &&  *pline >= '0' && *pline <= '9' )
				{
					n = n*10 + (*pline-'0');
					pline++;
                }
                // find it from string table
                find_str_in_table( n );
            }
			else
				printf("%c",*pline++ );
	    }
	    printf("\n");
	}
	return 0;
}
void visit(list<u32> &lin, u32 node, vector<set<u32> > &g, vector<u32> &visited) {
	visited[node] = 1;
	if (!g[node].empty()) {
		for (set<u32>::iterator it = g[node].begin(); it != g[node].end(); it++) {
			if (visited[*it] == 0) {
				visit(lin, *it, g, visited);
				if (lin.front() != *it) {
					lin.clear();
					return;
				}
			} else if (visited[*it] == 1) {
				//found cycle
				return;
			}
		}
	}
	visited[node] = 2;
	lin.push_front(node);
}
Example #25
0
 void set(int key, int value) {
     // Cache value for given key could be updated!
     unordered_map<int,LI>::const_iterator it = key2addr.find(key);
     if(it != key2addr.end())
     {
         refreshEntry(it->second, value);
     }
     else
     {
         if(size == cap)
             replaceLRU(key, value);
         else
         {
             LRUlist.push_front({key,value});
             key2addr[key] = LRUlist.begin();
             size++;
         }
     }
 }
Example #26
0
void RootExpression::createEvaluations() {
	evaluations.push_front(new CodeMaxExpression(KW_R2));
	evaluations.push_front(new CodeMinExpression(KW_R1));
	evaluations.push_front(new VMaxExpression(KW_V2));
	evaluations.push_front(new VMinExpression(KW_V1));

	evaluations.push_front(new ProxyExpression(KW_S0, new EvalS0()));
	evaluations.push_front(new ProxyExpression(KW_S1, new EvalS1()));
	evaluations.push_front(new ProxyExpression(KW_S2, new EvalS2()));
	evaluations.push_front(new ProxyExpression(KW_DT, new EvalDT()));
	evaluations.push_front(new DecimExpression(KW_DECIM));
	evaluations.push_front(
		new ProxyExpression(KW_STRIDE,new EvalStride()));
}
Example #27
0
//Places (i.e. generates coordinates for) a fruit
void placeFruit(int gameTime, list<fruit_t> &fruitMarket,deque<coord_t> &snake, int youngest)
{
	//Get size of window
	int row,col;
	getmaxyx(stdscr,row,col);
	coord_t randomCoord(-1,-1);
	bool inSomething = true;
	
	//Generate coordinates of fruit such that they aren't in the snake or on any other fruit
	while(inSomething == true)
	{
		randomCoord = coord_t((rand() % (row-3))+2,(rand() % (col-2))+1);
		
		for(deque<coord_t>::iterator i = snake.begin(); i != snake.end(); i++)
		{
			if((*i) == randomCoord)
			{
				inSomething = true;
				break;
			}
			else inSomething = false;
		}
		if(inSomething == true) continue;
		
		for(list<fruit_t>::iterator i = fruitMarket.begin(); i != fruitMarket.end(); i++)
		{
			if((*i).position == randomCoord)
			{
				inSomething = true;
				break;
			}
			else inSomething = false;
		}
	}
	
	//Create the fruit
	int creation_time;
	do {
		creation_time = youngest + int(exponential(rate));
	} while (creation_time <= gameTime); //generate next birthday of fruit; make sure it is in the future
	fruitMarket.push_front(fruit_t(randomCoord,creation_time,creation_time+30,10));//put new fruit on market
}
Example #28
0
/****************************************************************************
 * Function:   cbSnowball
 *             Callback function called when the Position Service receive a
 *             "SNOWBALL" message
 ****************************************************************************/
void cbSnowball (CMessage &msgin, const std::string &serviceName, TServiceId sid)
{
	static uint32 snowballId = START_SNOW_ID;

	uint32  playerId;
	CVector start,
			target;
	float   speed,
			explosionRadius;

	// Extract the incomming message content from the Frontend and print it
	msgin.serial( playerId );
	msgin.serial( start );
	msgin.serial( target );
	msgin.serial( speed );
	msgin.serial( explosionRadius );
	nldebug( "SB: Received SNOWBALL line." );

	// Store new snowballs information
	CTrajectory traj;
	traj.init( start, target, speed, CTime::getLocalTime() + THROW_ANIM_OFFSET );
	_snowball snowball = _snowball( snowballId, playerId, traj, explosionRadius );
	snoList.push_front( snowball );

	// Prepare to send back the message.
	CMessage msgout( "SNOWBALL" );
	msgout.serial( snowballId );
	msgout.serial( playerId );
	msgout.serial( start );
	msgout.serial( target );
	msgout.serial( speed );
	msgout.serial( explosionRadius );

	snowballId++;

	/*
	 * Send the message to all the connected Frontend.
	 */
	CUnifiedNetwork::getInstance ()->send( "FS", msgout );

	nldebug( "SB: Send back SNOWBALL line." );
}
 void op(string& opCode)
 {
   if(s.size() >= 2) {
     double a = s.front(); s.pop_front();
     double b = s.front(); s.pop_front();
     double result;
          if(opCode == "+")  result = b + a;
     else if(opCode == "-")  result = b - a;
     else if(opCode == "*")  result = b * a;
     else if(opCode == "/")  result = b / a;
     else if(opCode == "%")  result = fmod(b, a);
     else {
       cout << "unknown operator " << opCode << endl;
       return;
     }
     cout << result << endl;
     s.push_front(result);
   } else
     cout << "need two numbers\n";
 }
Example #30
0
File: 2d.cpp Project: pikle6/OpenGL
void mouse(int btn, int state, int x, int y){
    y = 480-y;
    if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && enter)
    {
        points* temp = new points(x,y);
        in.push_front(temp);
        glBegin(GL_POINTS);
            glVertex2i(x,y);
        glEnd();
        glFlush();
    }
    if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && sc)
    {
        sx = x; sy = y;
    }
    if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && rot)
    {
        rx = x; ry = y;
    }
}