Exemple #1
0
static void push_ourlqueue(Url * ourl)
{
    pthread_mutex_lock(&oq_lock);
    ourl_queue.push(ourl);
    if (ourl_queue.size() == 1)
        pthread_cond_broadcast(&oq_cond);
    pthread_mutex_unlock(&oq_lock);
}
Exemple #2
0
void showMeAdapterSizes(queue <Slav *> queue, stack <Slav *> stack)
{
	printf("[queue_size = %lu, stack_size = %lu, existingSlavs = %i]\n",
		queue.size(),
		stack.size(),
		Slav::counter());

}
 // Push element x onto stack.
 void push(int x) {
     _.push(x);
     for (int i = 0; i < _.size() - 1; i++)
     {
         _.push(_.front());
         _.pop();
     }
 }
void XN_CALLBACK_TYPE handDestroy(HandsGenerator &generator, XnUserID user, XnFloat fTime, void *pCookie){
	printf("hand destroy \n");
	if (hand1ID == user) {
		hand1ID = -1;
		while (hand1.size() > 0) {
			hand1.pop();
		}
	} else if (hand2ID == user) {
		hand2ID = -1;
		while (hand2.size() > 0) {
			hand2.pop();
		}
	}
	oldZoom = 1;
	oldAngle = 0;
	g_GestureGenerator.AddGesture(GESTURE_TO_USE, NULL);
}
Exemple #5
0
void Stack::pop(){
    while(q1.size() != 1){
        q2.push(q1.front());
        q1.pop();
    }
    q1.pop();
    swap(q1, q2);
}
void XN_CALLBACK_TYPE handUpdate(HandsGenerator &generator, XnUserID user, const XnPoint3D *pPosition, XnFloat fTime, void *pCookie){

	if (hand1ID == user) {
		if (hand1.size() > 2) {
			hand1.pop();
		}
		hand1.push(*pPosition);
	} else if (hand2ID == user) {
		
		if (hand2.size() > 2) {
			hand2.pop();
		}
		hand2.push(*pPosition);
	}

	//printf("handUpdate: x %f y %f z %f \n", pPosition->X, pPosition->Y, pPosition->Z);
}
    // Removes the element on top of the stack.
    void pop() {
        int len = my_que_A.size();
	    for(int i=0; i<len-1; i++) {
			my_que_A.push(my_que_A.front());
			my_que_A.pop();
	    }
		my_que_A.pop();
    }
Exemple #8
0
int main(int argc, const char * argv[]) {
    // insert code here...
    url_t output_url;
    output_url = parse_single_URL(argv[1]);
    depth=atoi(argv[2]);
    urlStruct init;
    init.url=output_url;
    urlQueue.push(init);
    
    
    
    for (int i=0; i<10; i++) {
        while(!urlQueue.empty()){
            
            
            
            urlStruct nextUrl=urlQueue.front();
            urlQueue.pop();
            
            
            dataStruct temp1 = retrieveWebPage(nextUrl.url, nextUrl.depth);
            if (temp1.data) {
                dataQueue.push(temp1);
                
            }
        }
        
        if (!dataQueue.empty()) {
            std::cout<<"\n DATAQUEUE SIZE:"<<dataQueue.size()<<"\n";
            dataStruct data=dataQueue.front();
            dataQueue.pop();
            
            parseWebPage(data);
            std::cout<<"\n"<<urlQueue.size()<<"\n";
            
            numberInQueue--;
            
        }
    
        
    }
    
    
    return 0;
}
 // Push element x onto stack.
 void push(int x) {
   size_t size = q.size();
   q.push(x);
   for( ; size > 0; --size ) {
     int tmp = q.front();
     q.pop();
     q.push(tmp);
   }
 }
 // Removes the element on top of the stack.
 void pop() {
     queue<int> tmp;
     int length = stack.size() - 1;
     for (int i = 0; i < length; i++) {
         tmp.push(stack.front());
         stack.pop();
     }
     stack = tmp;
 }
	string poo()
	{
		if (foodBuffer.size() == 0)
			throw petHungryException;

		string ans = foodBuffer.front();
		foodBuffer.pop();
		return ans;
	}
Exemple #12
0
int main(){
	ios_base::sync_with_stdio(false);
	cin >> h >> t >> r;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int fi, se;
		cin >> fi >> se;
		a[i] = MP(fi, se);
	}
	cin >> m;
	for(int i = 1; i <= m; i++){
		int fi, se;
		cin >> fi >> se;
		b[i] = MP(fi, se);
	}
	Q.push(MP(h, t));
	mark[h][t] = true;
	while(Q.size()){
		pie v = Q.front();
		Q.pop();
		if(v == MP(0, 0)){
			cout << "Ivan" << endl;
			cout << he[0][0] << endl;
			return 0;
		}
		for(int i = 1; i <= min(v.L, n); i++){
			pie u = v;
			u.L -= i;
			u.L += a[i].L;
			u.R += a[i].R;
			if(mark[u.L][u.R])
				continue;
			if(u.L + u.R <= r){
				he[u.L][u.R] = he[v.L][v.R] + 1;
				mark[u.L][u.R] = true;
				Q.push(u);
			}
		}
		for(int i = 1; i <= min(v.R, m); i++){
			pie u = v;
			u.R -= i;
			u.R += b[i].R;
			u.L += b[i].L;
			if(mark[u.L][u.R])
				continue;
			if(u.L + u.R <= r){
				he[u.L][u.R] = he[v.L][v.R] + 1;
				mark[u.L][u.R] = true;
				Q.push(u);
			}
		}
	}
	dfs(MP(h, t));
	cout << "Zmey" << endl
		<< DP(MP(h, t)) << endl;
	return 0;
}
 // Removes the element on top of the stack.
 void pop() {
     queue<int> tmp;
     while(q.size() > 1){
         int x = q.front();
         q.pop();
         tmp.push(x);
     }
     q = tmp;
 }
void pop(){
    for(int i = 0; i<q.size()-1;i++)
    {
        int top = q.front();
        q.pop();
        q.push(top);
    }
    q.pop();
}
void dequeue()
{
    if(q1.size()==0)
    {
        cout<<"underflow"<<endl;
        return;
    }
    while(q1.size()!=1)
    {
        q2.push(q1.front());
        q1.pop();
    }
    cout<<"popped element"<<q1.back()<<endl;
    q1.pop();
    temp=q2;
    q2=q1;
    q1=temp;
}
Exemple #16
0
 void pop(int& data) {
     {
         unique_lock<mutex> lk(m);
         cv.wait(lk,[this](){ return data_queue.size()>0; });
         data = data_queue.front();
         data_queue.pop();
     }
     cv.notify_all();
 }
Exemple #17
0
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	memset(h, -1, sizeof h);
	cin >> n;
	n++;
	all.PB(po[0].R.L);
	for(int i = 1; i < n; i++){
		int x, y, xx, yy;
		cin >> x >> y >> xx >> yy;
		po[i].L.L = x;
		po[i].L.R = y;
		po[i].R.L = xx;
		po[i].R.R = yy;
		all.PB(po[i].R.L);
	}
	sort(all.begin(), all.end());
	all.resize(unique(all.begin(), all.end()) - all.begin());
	for(int i = 0; i < n - 1; i++)
		s[idof(po[i].R.L)].insert(MP(po[i].R.R, i));
	build();
	
	//bfs :p
	Q.push(n - 1);
	h[n - 1] = 0;
	while(Q.size() and Q.front()){
		int v = Q.front();
		Q.pop();
		int id = idof(po[v].L.L);
		while(get(id) >= po[v].L.R){
			int lo = id, hi = sz(all);
			while(hi - lo > 1){
				int mid = (lo + hi) >> 1;
				get(mid) >= po[v].L.R ? lo = mid : hi = mid;
			}
			while(sz(s[lo]) and s[lo].begin()->L >= po[v].L.R){
				int u = s[lo].begin()->R;
				s[lo].erase(s[lo].begin());
				Q.push(u);
				h[u] = h[v] + 1;
				par[u] = v;
			}
			modify(lo);
		}
	}
	if(h[0] == -1){
		cout << -1 << endl;
		return 0;
	}
	cout << h[0] << endl;
	int v = 0;
	do{
		cout << (v = par[v]) << ' '; 
	}while(v != n - 1);
	cout << endl;
	return 0;
}
Exemple #18
0
void permute (stack<char> &prefix, queue<char> &suffix, int &perm_count) {

	if(suffix.size() == 0) {
	//if it is required to print all combinations of lenght "n", then insted of suffix.size() == 0, check prefix.size() == n
		print_stack(prefix);
		perm_count++;
		return;
	}
	for(int i = 0; i < suffix.size(); i++) {
		char c = suffix.front();
		suffix.pop();
		prefix.push(c);
		permute(prefix, suffix, perm_count);
		c = prefix.top();
		prefix.pop();
		suffix.push(c);
	}
}
void send_messages(unordered_map<int, vector<forward_entry>> &forward_table) {
    // int i;
    // for(i = 0; i < allmessages.size(); i++){
    while(allmessages.size() > 0) {
        int source, dest;
        source = allmessages.front()->source;
        dest = allmessages.front()->destination;
        //initial output
        outfile << "from " << source << " to " << dest << " hops ";
        //calculate next hops

        //need to look at hash map of forward tables, recursively choose nexthop
        queue<int> pathhops; //store current path of hops
        pathhops.push(source);
        //int temp = source;
        int vectorindex = 0;
        vector<forward_entry> cur_table = forward_table[source];
        bool isreachable = false;
        while(cur_table[vectorindex].destination != dest && vectorindex < cur_table.size()) {
            vectorindex++;
        }
        if(cur_table[vectorindex].pathcost != -1) {
            isreachable = true;
        }
        if(isreachable) {
            int nexthop = cur_table[vectorindex].nexthop;
            if(nexthop != dest) {
                pathhops.push(nexthop);
            }
            while(nexthop != dest) {
                cur_table = forward_table[nexthop];
                vectorindex = 0;
                while(cur_table[vectorindex].destination != dest && vectorindex < cur_table.size()) {
                    vectorindex++;
                }
                nexthop = cur_table[vectorindex].nexthop;
                if(nexthop != dest) {
                    pathhops.push(nexthop);
                }
            }
            //now have hop path so need to print it out
            while(pathhops.size() > 0) {
                outfile << pathhops.front() << " ";
                pathhops.pop();
            }
            outfile << "message" << allmessages.front()->message << "\n";
            allmessages.pop();
        }
        //case where message cant be sent to destination
        else {
            outfile << "unreachable message" << allmessages.front()->message << "\n";
            allmessages.pop();
        }
    }
    outfile << "\n";
}
int Dijkstra()
{
    for ( int i = 1; i <= N; ++i )
        for ( int j = 1; j <= N; ++j )
            D[i][j] = INF;

    D[1][1] = 0;
    Q.push( Edge(1, 1) );
    in_q[1][1] = true;

    int sol = INF;

    while ( Q.size() )
    {
        Edge p = Q.front();
        Q.pop();

        int nod = p.nod;
        int dragon = p.cost;

        in_q[nod][dragon] = false;

        if ( nod == N )
        {
            sol = min(sol, D[nod][dragon]);
            continue;
        }

        for ( unsigned i = 0; i < G[nod].size(); ++i )
        {
            int son = G[nod][i].nod;
            int cost = G[nod][i].cost;

            if ( Dmax[dragon] >= cost )
            {
                int aux_drg = dragon;

                if ( Dmax[son] > Dmax[dragon] )
                    aux_drg = son;

                if ( D[son][aux_drg] > D[nod][dragon] + cost )
                {
                    D[son][aux_drg] = D[nod][dragon] + cost;

                    if ( !in_q[son][aux_drg] )
                    {
                        in_q[son][aux_drg] = true;
                        Q.push( Edge( son, aux_drg ) );
                    }
                }
            }
        }
    }

    return sol;
}
 void traversalTree(queue<TreeNode *> traverse_list, vector<int>& v) {
     queue<TreeNode *> to_traverse_list;
     while(traverse_list.size()>0) {
         TreeNode* node = traverse_list.front();
         if(node->left)
             to_traverse_list.push(node->left);
         if(node->right)
             to_traverse_list.push(node->right);
             
         if(traverse_list.size()==1) {
             TreeNode *node = traverse_list.front();
             traverse_list.pop();
             v.push_back(node->val);
             traverse_list = to_traverse_list;
             clear(to_traverse_list);
         }else
             traverse_list.pop();
     }
 }
Exemple #22
0
int myStack::pop(){
    int ele ; 
    if(Q.size()==0 && Q_temp.size()==0)
        cout<<"\nError No elements to pop !" <<endl; 

    else{
            while(Q.size()>1) { 
                Q_temp.push(Q.front()) ; Q.pop() ; 
            }

            ele = Q.front() ; 
            Q.pop() ; 

            while(!Q_temp.empty()) { 
                Q.push(Q_temp.front()) ; Q_temp.pop() ; 
            }
    }
    return ele ; 
}
Exemple #23
0
void Print::ToPrintQueue( queue<string> ToStringQueue)	//输出得到的队列 
{
    
    int  n = ToStringQueue.size(),j;          //队列的长度 
    for(j=0;j<n;j++)             	
    {
        cout << ToStringQueue.front() <<endl;	//输出队列的首个元素 
         ToStringQueue.pop();   //弹出队列的第一个元素 
    }
}
 // Push element x onto stack.
 void push(int x) {
     int len = que.size();
     que.push(x);
     int i = 0;
     while(i++<len)
     {
         que.push(que.front());
         que.pop();
     }
 }
Exemple #25
0
		//take a single random training vector and impress it on the SOM
		//training vectors are arranged in the queue (trainingBuffer) to ensure even distribution of training impressions
		void trainStep(){
				if(trainingBuffer.size()>0){
					vector<float> singleTrainingVector = trainingBuffer.front();
					trainingBuffer.pop();
					int BMU = findBMU(singleTrainingVector);
					trainNeighbors(singleTrainingVector, BMU, train_current/(float)train_max, train_current/(float)train_max);
				}else{
					fillTrainingBuffer();
				}
		}
void permutations(queue<T>& q, stack<T>& s){
	int size = q.size();
	if(q.empty()){cout << s << '\n'; return;}
	for(unsigned int i = 0; i < size; i++){
		s.push(q.front()); q.pop();
		cout << "permcall" << i << endl;
		permutations(q, s);
		q.push(s.top()); s.pop();
	}
}
 /** Removes the element on top of the stack and returns that element. */
 int pop() {
     queue<int> tmpQue;
     while(que.size() > 1) {
         last = que.front();
         tmpQue.push(que.front());
         que.pop();
     }
     swap(tmpQue, que);
     return tmpQue.front();
 }
Exemple #28
0
void output_queue(queue <int> Q) {
	int quantity = Q.size(), temp;
	for (int i = 0; i < quantity; i++) {
		temp = Q.front();
		Q.push(temp);
		printf("%d ", temp+1);
		Q.pop();
	}

}
 // Removes the element on top of the stack.
 void pop() {
     int temp;
     while(q1.size()!=1){
     	temp = q1.front();
     	q2.push(temp);
     	q1.pop();
     } 
     q1.pop();
     swap(q1,q2);
 }
Exemple #30
0
 void spfa() {
   while(q.size()) {
     int u = q.front()/MAX,s = q.front()%MAX; q.pop();
     in[u][s] = false;
     for(Edge *e = vertex[u];e;e = e->next)
       if( update(e->v,s|g[e->v],dp[u][s]+e->w) &&
           s==(s|g[e->v]) && !in[e->v][s])
         q.push(e->v*MAX+s), in[e->v][s] = true;
   }
 }