当前位置: 首页>>代码示例>>C++>>正文


C++ queue::front方法代码示例

本文整理汇总了C++中queue::front方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::front方法的具体用法?C++ queue::front怎么用?C++ queue::front使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在queue的用法示例。


在下文中一共展示了queue::front方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BFS

int BFS()
{
    int i,tmp,min,tmppre;
    for(i=0;i<=m+1;i++)
    {
        vis[i]=false;
        pre[i]=-1;
    }
    vis[0]=true;
    while(!Q.empty())
        Q.pop();
    Q.push(0);
    while(!Q.empty())
    {
        tmp=Q.front();
        Q.pop();
        for(i=1;i<=m+1;i++)
        {
            if(i==tmp || vis[i] || !map[tmp][i])
                continue;
            vis[i]=true;
            pre[i]=tmp;
            Q.push(i);
        }
    }
    if(pre[m+1]==-1)
        return -1;
    min=INF,tmp=m+1;
    while((tmppre=pre[tmp]) != -1)
    {
        if(map[tmppre][tmp]<min)
            min=map[tmppre][tmp];
        tmp=tmppre;
    }
    return min;
}
开发者ID:Noodle3D,项目名称:ZCookie,代码行数:36,代码来源:POJ1637+Sightseeing+tour.cpp

示例2: find

int find(){
	memset(map,0,sizeof(map));
	while(!que.empty())que.pop();
	begin.step=0;
	que.push(begin);
	int x,y,step;
	while(!que.empty()){
		tmp=que.front();
		x=tmp.x,y=tmp.y,step=tmp.step;
		que.pop();
		if(x==end.x && y==end.y)break;
		for(int i=0;i<8;i++){
			tmp.x=x+str[i][0];
			if(tmp.x<0 || tmp.x>=m)continue;
			tmp.y=y+str[i][1];
			if(tmp.y<0 || tmp.y>=m)continue;
			if(map[tmp.x][tmp.y])continue;
			map[tmp.x][tmp.y]=1;
			tmp.step=step+1;
			que.push(tmp);
		}
	}
	return step;
}
开发者ID:chyyuu,项目名称:ACM,代码行数:24,代码来源:10257897_AC_110MS_344K.cpp

示例3: Spfa

	void Spfa() {
		for (int i = 0; i <= n; i++)
			inq[i] = 0, dist[i] = INF;
			
		dist[st] = 0, inq[st] = 1;
		Q.push(st);
		while (!Q.empty()) {
			int u = Q.front(); Q.pop();
			inq[u] = 0;
			for (Edge *i = adj[u]; i != NULL; i = i->next) {
				if (i->cap == 0 || dist[i->v] <= dist[u] + i->cost)
					continue;
				dist[i->v] = dist[u] + i->cost;
				if (!inq[i->v]) {
					inq[i->v] = 1;
					Q.push(i->v);
				}
			}
		}
		
		int ded = dist[ed];
		for (int i = 0; i <= n; i++)
			dist[i] = ded - dist[i];
	}
开发者ID:morris821028,项目名称:UVa,代码行数:24,代码来源:1104+-+Chips+Challenge.cpp

示例4: main

int main()
{
	int n,d;
	while(scanf("%d",&n)==1){
		while(n--){
			scanf("%d",&d);
			s.push(d);
			t.push(d);
		}
		printf("队列正向输出:");
		while(!s.empty()){
			printf(" %d",s.front());
			s.pop();
		}
		printf("\n");
		printf("堆栈逆向输出:");
		while(!t.empty()){
			printf(" %d",t.top());
			t.pop();
		}
		printf("\n");
	}
	return 0;
}
开发者ID:mainboy,项目名称:algorithm,代码行数:24,代码来源:queue_stack.c

示例5: bfs

int bfs(){
	q.push((node){a,0});
	mp[a]=1;
	while(!q.empty()){
		node t=q.front();q.pop();
		if(t.t>=10)return -1;
		string S=t.s;
		for(int i=1;i<=n;i++){
			int x=S.find(str[i][0],0);
			while(x!=string::npos){
				S.replace(x,str[i][0].size(),str[i][1].c_str(),str[i][1].size());
				if(!mp[S]){
					if(b==S)return t.t+1;
					node d=(node){S,t.t+1};
					q.push(d);
					mp[S]=1;
				}
				S=t.s;
				x=S.find(str[i][0],x+1);
			}
		}
	}
	return -1;//注意这里 
}
开发者ID:ClearDreamer,项目名称:OI,代码行数:24,代码来源:1099.cpp

示例6: AddTimeSlot

void CReplay :: AddTimeSlot( uint16_t timeIncrement, queue<CIncomingAction *> actions )
{
	BYTEARRAY Block;
	Block.push_back( REPLAY_TIMESLOT );
	UTIL_AppendByteArray( Block, (uint16_t)0, false );
	UTIL_AppendByteArray( Block, timeIncrement, false );

	while( !actions.empty( ) )
	{
		CIncomingAction *Action = actions.front( );
		actions.pop( );
		Block.push_back( Action->GetPID( ) );
		UTIL_AppendByteArray( Block, (uint16_t)Action->GetAction( )->size( ), false );
		UTIL_AppendByteArrayFast( Block, *Action->GetAction( ) );
	}

	// assign length

	BYTEARRAY LengthBytes = UTIL_CreateByteArray( (uint16_t)( Block.size( ) - 3 ), false );
	Block[1] = LengthBytes[0];
	Block[2] = LengthBytes[1];
	m_CompiledBlocks += string( Block.begin( ), Block.end( ) );
	m_ReplayLength += timeIncrement;
}
开发者ID:0x6d48,项目名称:ghostpp,代码行数:24,代码来源:replay.cpp

示例7: bfs

int bfs(int ci,int x,int y)
{
    w[ci][x][y].mark=1;
    node1 e;
    e.c1=ci;
    e.x1=x;
    e.y1=y;
    q.push(e);
    while(!q.empty())
    {
        node1 r=q.front();
        q.pop();
        int step=w[r.c1][r.x1][r.y1].num;
        for(int ll=0;ll<6;ll++)
        {
            int cc,yy,xx;
            cc=r.c1+dir[ll][0];
            xx=r.x1+dir[ll][1];
            yy=r.y1+dir[ll][2];
            if((cc<0||cc>=k||xx<0||xx>=m||yy<0||yy>=n)||w[cc][xx][yy].mark||s[cc][xx][yy]=='#')continue;
            else
            {

                w[cc][xx][yy].mark=1;
                w[cc][xx][yy].num=step+1;
                if(s[cc][xx][yy]=='E')return step+1;
                node1 t;
                t.c1=cc;
                t.x1=xx;
                t.y1=yy;
                q.push(t);
            }
        }
    }
    return 0;
}
开发者ID:xiammu,项目名称:acm,代码行数:36,代码来源:poj+2251.cpp

示例8: processIPResponse

void processIPResponse(string myname, string msg, queue<string> &pendingPrivateMessages) {
	string host, port, ppm;
	int sock, iport;

	if (!pendingPrivateMessages.size()) {
		cerr << "bailing out of IPResponse.  no pending messages" << endl;
		return;
	}
	if (!parse(msg, host, port)) {
		cerr << "Failed to send private message" << endl;
		pendingPrivateMessages.pop();	
		return;
	}
	iport = atoi(port.c_str());
	if ((sock = connectToServer(host.c_str(), iport, SOCK_DGRAM)) < 0) {
		cerr << "Couldn't connect to " << host << ":" << port << " for private message." << endl;
		pendingPrivateMessages.pop();
		return;
	}
	ppm = pendingPrivateMessages.front();
	ppm = "PeerMessage " + myname + " " + ppm;
	pendingPrivateMessages.pop(); 
	socketSend(sock, ppm);
}
开发者ID:ikeed,项目名称:school,代码行数:24,代码来源:client.cpp

示例9: augment_path

int augment_path(int s, int t)
{
	memset(from, -1, sizeof(from));

	from[s] = s;
	Q.push(s);
	while(!Q.empty())
	{
		int u = Q.front();
		Q.pop();
		for(int v = 0; v < MAX; v++)
		{
			if(from[v] != -1) continue;
			if(cap[u][v] == 0) continue;
			from[v] = u;
			Q.push(v);
		}
	}
	if(from[t] == -1) return 0;

	int flow = cap[from[t]][t];
	for(int v = t; v != s; v = from[v])
	{
		int u = from[v];
		flow = min(flow, cap[u][v]);
	}

	for(int v = t; v != s; v = from[v])
	{
		int u = from[v];
		cap[u][v] -= flow;
		cap[v][u] += flow;
	}

	return flow;
}
开发者ID:1ridescent,项目名称:ACM,代码行数:36,代码来源:I.cpp

示例10: reach

int reach(int limit) {
	memset(d, -1, sizeof(d));
	while (!Q.empty())
		Q.pop();

	d[sx][sy] = 0;
	Q.push(MP(sx, sy));
	while (!Q.empty()) {
		pair<int, int> cur = Q.front();
		Q.pop();
		int x = cur.first, y = cur.second;

		for (int k = 0; k < 4; k++) {
			int xx = x + dx[k], yy = y + dy[k];

			if (!check(xx, yy)) continue;
			if (dist[xx][yy] < limit || d[xx][yy] >= 0) continue;

			d[xx][yy] = d[x][y] + 1;
			Q.push(MP(xx, yy));
		}
	}
	return d[ex][ey] >= 0;
}
开发者ID:Dao007forever,项目名称:acmicpc,代码行数:24,代码来源:3975.cpp

示例11: bfs

/**
 * 2. Breadth First Search
 */
bool bfs(int src, int dest = V+1) {
  visited.clear();
  visit_order.clear(); // optional
  queue<int>().swap(que); // clear queue `que` by swapping it with an empty one

  que.push(src);

  while(!que.empty()) {
    int u = que.front();
    que.pop();

    if(visited.count(u) > 0) continue;

    visited.insert(u);
    visit_order.push_back(u); // optional

    if(u == dest) return true;

    for(auto &v: g[u])
      que.push(v);
  }

  return false;
}
开发者ID:babhishek21,项目名称:oj-sols,代码行数:27,代码来源:graph_traversals.cpp

示例12: insert

void insert(int &rt,int num)
{
    if(rt==0)
    {
        rt=Q.front();
        Q.pop();
        LL(rt)=RR(rt)=0;
        tot[rt]=1;
        v[rt]=num;
        begin[rt]=end[rt]=num;
        ans[rt]=num;
        return;
    }
    tot[rt]++;
    if(num<v[rt])
        insert(LL(rt),num);
    else
        insert(RR(rt),num);
    update(rt);
    if(num<v[rt])
        Maintain(rt,false);
    else
        Maintain(rt,true);
}
开发者ID:okcd00,项目名称:ACM_Road,代码行数:24,代码来源:sol-zhan.cpp

示例13: mcmf

int TaskMgr::mcmf(int s,int t){
	int flow=0;
	while(true){
		memset(pre,-1,sizeof(pre));
		memset(vis,false,sizeof(vis));
		memset(wgt,0x7f,sizeof(wgt));
		wgt[s]=0;
		que.push(s);
		while(!que.empty()){
			int u=que.front(); que.pop();
			vis[u]=false;
			for(int i=head[u];~i;i=E[i].next){
				int v=E[i].vtx;
				if(E[i].cap&&wgt[u]+E[i].wgt<wgt[v]){
					wgt[v]=wgt[u]+E[i].wgt;
					if(!vis[v]){
						vis[v]=true;
						que.push(v);
					}
					pre[v]=u; cur[v]=i;
				}
			}
		}
		if(pre[t]==-1) break;
		int mf=0x7fffffff;
		for(int v=t;v!=s;v=pre[v]){
			mf=min(mf,E[cur[v]].cap);
		}
		for(int v=t;v!=s;v=pre[v]){
			E[cur[v]].cap-=mf;
			E[cur[v]^1].cap+=mf;
		}
		flow+=mf;
	}
	return flow;
}
开发者ID:AmbBAI,项目名称:JunkCode,代码行数:36,代码来源:AI+-+stable.cpp

示例14: pickup_from_queue

void pickup_from_queue(queue<midi_message_t>& queue,
                       void *jack_midi_buffer,
                       struct timespec& prev_cycle,
                       struct timespec& cycle_period,
                       jack_nframes_t nframes
                       )
{
    jack_nframes_t last_framepos = 0;

    while(!queue.empty()) {
        midi_message_t msg = queue.front();
        long nsec_since_start = diff(prev_cycle, msg.time).tv_nsec;
        long framepos = (nsec_since_start * nframes) / cycle_period.tv_nsec;
        if (framepos <= last_framepos) {
            framepos = last_framepos + 1;
        }

        if (framepos >= nframes) {
            framepos = nframes - 1;
        }

        if (state == LISTEN && &queue == &controller_queue) {
            process_controller_out_message(msg);
        }

        uint8_t *buffer = jack_midi_event_reserve(jack_midi_buffer, framepos, msg.buffer.size());
        if (buffer) {
            memcpy(buffer, msg.buffer.data(), msg.buffer.size());
        } else {
            fprintf(stderr, "failed to allocate %d bytes midi buffer at framepos %ld (nframes = %d)",
                    msg.buffer.size(), framepos, nframes);
        }

        queue.pop();
    }
}
开发者ID:hansfbaier,项目名称:ultranova4linux,代码行数:36,代码来源:main.cpp

示例15: bfs

bool bfs() {
    memset(d,0x3f,sizeof(d));
    q.empty();

    for (int i=0; i<n; i++)
        currEdge[i]=lastEdge[i];

    q.push(s);
    d[s]=0;

    while (!q.empty()) {
        int u = q.front();
        q.pop();

        for (int i=lastEdge[u]; i!=-1; i=ls[i].prev)
            if (ls[i].c-ls[i].f>0 && d[ls[i].dst]==inf) {
                int v=ls[i].dst;
                d[v]=d[u]+1;
                q.push(v);
            }
    }

    return d[t]!=inf;
}
开发者ID:royalsflush,项目名称:lib-stalingrafo,代码行数:24,代码来源:dinic.cpp


注:本文中的queue::front方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。