本文整理汇总了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;
}
示例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;
}
示例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];
}
示例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;
}
示例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;//注意这里
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}