• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ queue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: enqueue_worklist_item

void enqueue_worklist_item(const worklist_item & item) {
  worklist.push(item);
}
开发者ID:Jornason,项目名称:DieHard,代码行数:3,代码来源:worklist.cpp


示例2: listen_t

void* listen_t(void *ptr)                    
                                             
{	sem_init(&mutexqueue,0,1);
	
	int n;
	socklen_t len;
	char *method, buff[1024];
	len=sizeof(current_socket.client);
	time_t it;

	
	incoming_request.type=0;
	while(1)
	{			
		
		char RequestPath[100]; FILE *tmp;struct stat attr;	
		incoming_request.connection=accept(current_socket.socket_id,(struct sockaddr *)& (current_socket.client),&len); 
		n=read(incoming_request.connection,buff,1024);

		char *z = buff;
		incoming_request.buffers = z;

		method=strtok(buff," ");
		incoming_request.path=strtok(NULL," ");
        	incoming_request.request_method=strtok(NULL,"\n");
		if(strcmp(method,"GET")==0)
			incoming_request.type=1;
		else if(strcmp(method,"HEAD")==0)
			incoming_request.type=2;
		else
			incoming_request.type=3;

		incoming_request.ip= (&current_socket.client)->sin_addr.s_addr;
		for (int i = 0; i < (incoming_request.path).length(); i++)
        	{
            		if (incoming_request.path[i] == '\n' || incoming_request.path[i] == '\r' )
                		incoming_request.path[i] = '\0';
        	}	
		strcpy(RequestPath,RootPath);
                const char* e = (incoming_request.path).c_str();
                strcat(RequestPath,e);
 		tmp = fopen(RequestPath,"r");
		if(tmp != NULL)
		{	
			fseek(tmp,0,SEEK_END);
			incoming_request.filesize=ftell(tmp);
			fclose(tmp);		
			incoming_request.status = 200;		
		}
		else
		{
			incoming_request.status = 404;incoming_request.filesize=0;					
		}				
		if(strcmp(method,"HEAD")==0)
		{
			incoming_request.filesize=0;
		}			
		time(&it);				
		stat(RequestPath, &attr);		
		incoming_request.LastModifiedTime=asctime(gmtime(&attr.st_mtime));
		incoming_request.IncomingTime=asctime(gmtime(&it));


				
		
		if(debug==1)
		{
			debug_request = incoming_request;			
			debugging_request();
		}

		else
		{

		
			sem_wait(&mutexqueue);
                        if (sched == 0) {
			readyQueue.push(incoming_request); 
                        }
                        else {
			readyQueueP.push(incoming_request); 
                        }
			sem_post(&mutexqueue);

		}
			       	
	}							
} 
开发者ID:puneetar,项目名称:Multi-threaded_Web_Server,代码行数:88,代码来源:main.cpp


示例3: enqueueCharacter

 void enqueueCharacter(char ch){
     q.push(ch);
 }
开发者ID:prashantpcm94,项目名称:Hackerrank-30-days-of-Code,代码行数:3,代码来源:Day18.cpp


示例4: gPushTouch

void gPushTouch( queue<TouchHolder> &touchQueue, TouchHolder touchHolder )
{
	touchQueue.push(touchHolder);
}
开发者ID:nvhausid,项目名称:Project1,代码行数:4,代码来源:Globals.cpp


示例5: dequeueCharacter

 char dequeueCharacter(){
     char c = q.front();
     q.pop();
     return c;
 }
开发者ID:prashantpcm94,项目名称:Hackerrank-30-days-of-Code,代码行数:5,代码来源:Day18.cpp


示例6: gPushKey

void gPushKey( queue<KeyHolder> &keyQueue, KeyHolder keyHolder )
{
	keyQueue.push(keyHolder);
}
开发者ID:nvhausid,项目名称:Project1,代码行数:4,代码来源:Globals.cpp


示例7: Java_cc_openframeworks_OFAndroid_render

/* Call to render the next GL frame */
void
Java_cc_openframeworks_OFAndroid_render( JNIEnv*  env, jclass  thiz )
{

	if(paused || surfaceDestroyed) return;

	if(!threadedTouchEvents){
		mutex.lock();
		queue<ofTouchEventArgs> events = touchEventArgsQueue;
		while(!touchEventArgsQueue.empty()) touchEventArgsQueue.pop();
		mutex.unlock();

		while(!events.empty()){
			switch(events.front().type){
			case ofTouchEventArgs::down:
				ofNotifyMousePressed(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchDown,events.front());
				break;
			case ofTouchEventArgs::up:
				ofNotifyMouseReleased(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchUp,events.front());
				break;
			case ofTouchEventArgs::move:
				ofNotifyMouseMoved(events.front().x,events.front().y);
				ofNotifyMouseDragged(events.front().x,events.front().y,0);
				ofNotifyEvent(ofEvents().touchMoved,events.front());
				break;
			case ofTouchEventArgs::doubleTap:
				ofNotifyEvent(ofEvents().touchDoubleTap,events.front());
				break;
			case ofTouchEventArgs::cancel:
				ofNotifyEvent(ofEvents().touchCancelled,events.front());
				break;
			}
			events.pop();
		}
	}

	ofNotifyUpdate();


	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->startRender();
	}
	int width, height;

	width  = sWindowWidth;
	height = sWindowHeight;

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	//glViewport( 0, 0, width, height );
	ofViewport(0, 0, width, height, false);		// used to be glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

	if ( bClearAuto == true || ofGetFrameNum() < 3){
		ofClear(bgPtr[0]*255,bgPtr[1]*255,bgPtr[2]*255, bgPtr[3]*255);
	}

	if(bSetupScreen) ofSetupScreen();
	ofNotifyDraw();

	if(ofGetGLProgrammableRenderer()){
		ofGetGLProgrammableRenderer()->finishRender();
	}

}
开发者ID:AnnaKolla,项目名称:openFrameworks,代码行数:69,代码来源:ofAppAndroidWindow.cpp


示例8: nextO

 void nextO(vector<vector<char>> &board, queue<pair<int, int>> &q, int i, int j, int m, int n) {
     if (i >= 0 && i < m && j >= 0 && j < n && board[i][j] == 'O') {
         board[i][j] = OUTER_O();
         q.push(pair<int, int>(i, j));
     }
 }
开发者ID:Moonshile,项目名称:AlgorithmCandy,代码行数:6,代码来源:130.cpp


示例9: run

// if user only inputs test, thats true, because
// we add the -e, in bash thats true...?
// so after we have detected the flag, char s will be
// everything after that until connector or end
void Test::run(queue<string>& q, bool& worked, bool brack) {
    // if no arguments after flag, then true
    // so, check it end of queue
    // or if a connector been detected
    //
    
    bool there;
    if (brack) {
        there = true;
    }

    // when ONLY "test" is entered or test and connector
    if (q.size() == 0 || isCon(q.front())) {
        cout << "(False)" << endl;
        worked = false;
        return;
    }

    if (q.front() == "]") {
        q.pop();
        cout << "(False)" << endl;
        worked = false;
        return;
    }

    if (q.front() == "-e") {  
        q.pop();

        if (q.size() == 0 && brack) {
            cout << "(False)" << endl;
            worked = false;
            return;
        }

        // removed additional true if for isCon
        if (q.size() == 0 || isCon(q.front())) {
            cout << "(True)" << endl;
            worked = true; 
            return; 
        }

        if (q.front() == "]") {
            q.pop();
            cout << "(True)" << endl;
            worked = true;
            return;
        }

        // keep checking
        string dir;
        while (q.size() != 0 && !(isCon(q.front()))) {
            // brack = false;
            if (q.front() == "]") {
                q.pop();
                brack = true;
            }
            else if (q.front() == ")") {
                q.pop();
            }
            else {
                brack = false;
                dir += q.front();    
                q.pop();
            }
        }


        if (!brack && there) {
            cout << "(False)" << endl;
            worked = false;
            return;
        }
        
        // const char* s = q.front().c_str();
        const char* s = dir.c_str();
        if (exists(s)) {
            cout << "(True)" << endl;
            worked = true; 
        }
        else {
            cout << "(False)" << endl;
            worked = false;
        }
        // q.pop();
    }

    else if (q.front() == "-f") {
       q.pop();

       if (q.size() == 0 && brack) {
           cout << "(False)" << endl;
           worked = false;
           return;
       } 

       if (q.size() == 0 || isCon(q.front())) {
//.........这里部分代码省略.........
开发者ID:mpho001,项目名称:rshell,代码行数:101,代码来源:Test.cpp


示例10: init

namespace MaxFlow {
    const int MAX_NODES = 1005;
 
    int SRC = 0, DEST = 1;
    int nodes = 2;
 
    int F[MAX_NODES][MAX_NODES], C[MAX_NODES][MAX_NODES];
    int Parent[MAX_NODES];
    queue<int> Q;
    vector<int> G[MAX_NODES];
 
    void init(int n, int s = -1, int d = -1) {
        if(s == -1) s = ++n;
        if(d == -1) d = ++n;
 
        SRC = s; DEST = d;
        nodes = n;
 
        for(int i=1; i<=nodes; i++) {
            for(auto vec : G[i]) {
                C[i][vec] = F[i][vec] = 0;
            }
            G[i].clear();
        }
    }
 
    void addEdge(int a, int b, int cap) {
        G[a].push_back(b);
        G[b].push_back(a);
        C[a][b] += cap;
    }
 
    bool bfs() {
        memset(Parent, 0, sizeof(Parent));
        Parent[SRC] = -1;
        Q.push(SRC);
 
        while(!Q.empty()) {
            int node = Q.front();
            Q.pop();
 
            for(auto vec : G[node]) {
                if(!Parent[vec] && F[node][vec] < C[node][vec]) {
                    Parent[vec] = node;
                    Q.push(vec);
                }
            }
        }
 
        return Parent[DEST] != 0;
    }
 
 
    int maxFlow() {
        int flow = 0;
        while(bfs()) {
            for(auto x : G[DEST]) {
                if(Parent[x] == 0) continue;
 
                int M = C[x][DEST] - F[x][DEST];
                for(int node = x; node != SRC; node = Parent[node]) {
                    M = min(M, C[Parent[node]][node] - F[Parent[node]][node]);
                }
 
                F[x][DEST] += M; F[DEST][x] -= M;
                for(int node = x; node != SRC; node = Parent[node]) {
                    F[Parent[node]][node] += M;
                    F[node][Parent[node]] -= M;
                }
 
                flow += M;
            }
        }
 
        return flow;
    }
};
开发者ID:bicsi,项目名称:code_snippets,代码行数:77,代码来源:maxflow_matrix.cpp


示例11: clear

void ofURLFileLoaderImpl::clear(){
	Poco::ScopedLock<ofMutex> lock(mutex);
	requests.clear();
	while(!responses.empty()) responses.pop();
}
开发者ID:BonjourDpt,项目名称:openFrameworks,代码行数:5,代码来源:ofURLFileLoader.cpp


示例12: push

 void push(U &&u)
 {
     boost::lock_guard<boost::mutex> l(m);
     q.push( boost::forward<U>(u) );
     c.notify_one();
 }
开发者ID:ElaraFX,项目名称:boost,代码行数:6,代码来源:await_emu.cpp


示例13: empty

 // Return whether the stack is empty.
 bool empty() {
     return left.empty() && right.empty();
 }
开发者ID:bestswifter,项目名称:LeetCode,代码行数:4,代码来源:+Implement+Stack+using+Queues.cpp


示例14: main

int main(int argc, char *argv[]) {
  ifstream ifs(argv[1]);
  while(1) {
    ifs >> column;
    ifs >> low; 
    if (low ==0 && column ==0) break;
    
    // init
    for(int i=0; i<low; ++i) {
      for(int j=0; j<column; ++j) {
        filed[i][j] = 1000;
      }
    }

    // mark own area
    int existing_num;
    ifs >> existing_num;
    point p;
    for(int i=0; i<existing_num; ++i) {
      int l,c;
      ifs >> c >> l;
      p.push_back(l-1);
      p.push_back(c-1);
      p.push_back(0);
      que.push(p);
      while(que.size() != 0) {
        setQue(que.front());
        que.pop();
      }
      p.clear();
    }
    
    // 初期化のためにコピー
    c_array();
    //debug();

    // culc plan 
    int plan_num;
    ifs >> plan_num;
    int ans=0;
    for(int i=0; i<plan_num; ++i) {
      int l,c;
      area = 0;
      ifs >> c >> l;
      p.push_back(l-1);
      p.push_back(c-1);
      p.push_back(0);
      que.push(p);
      while(que.size() != 0) {
        setQue(que.front());
        que.pop();
      }
      p.clear();
      if (ans < area) {
        ans = area;
      }
      // 予定地分もメモに記憶させているので初期化
      rec_array();
    }
    cout << ans << endl;
  }
}
开发者ID:sunofly,项目名称:cpp,代码行数:62,代码来源:test.cpp


示例15: pop

 // Removes the element on top of the stack.
 void pop() {
     left.empty() ? right.pop() : left.pop();
 }
开发者ID:bestswifter,项目名称:LeetCode,代码行数:4,代码来源:+Implement+Stack+using+Queues.cpp


示例16: main

int main()
{
	int n;	cin>>n;
	int cntR=0,cntl=0;
	m.clear();
	while(!q.empty())q.pop();
	string s,s1,s2;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		int cr=0;
		for(int i=0;i<s.length();i++) 
		{
			s[i]=tolower(s[i]);
			if (s[i]=='r') cr++;
		}
		//cout<<s<<cr<<endl;
		q.push(MP(s,cr));
	}
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s1>>s2;
		int cr1=0;
		for(int i=0;i<s1.length();i++)
		{
			s1[i]=tolower(s1[i]);
			if (s1[i]=='r') cr1++;
		}
		int cr2=0;
		for(int i=0;i<s2.length();i++)
		{
			s2[i]=tolower(s2[i]);
			if (s2[i]=='r') cr2++;
		}
		//cout<<s1<<cr1<<s2<<cr2<<endl;
		m.insert(pss(MP(s1,cr1),MP(s2,cr2)));
	}
	while(!q.empty())
	{
		psi tmp=q.front();
		q.pop();
		if(m[tmp].first=="")
		{
			cntl+=tmp.first.length();
			cntR+=tmp.second;
		}
		else
		{
			int cntr1=tmp.second;
			int cntr2=m[tmp].second;
			int len1=tmp.first.length();
			int len2=m[tmp].first.length();
			
			if(cntr2<cntr1) cntR+=cntr2,cntl+=len2;
			else if(cntr2==cntr1) cntR+=cntr2,cntl+=(len1>len2?len2:len1);
			else cntR+=cntr1,cntl+=len1; 
			//cout<<cntr1<<cntr2<<cntR<<endl;
			//cout<<len1<<len2<<cntl<<endl;
		}
	}
	cout<<cntR<<" "<<cntl<<endl;
	return 0;
}
开发者ID:okcd00,项目名称:ACM_Road,代码行数:64,代码来源:dano.cpp


示例17: main

int main()
{
	ifstream fin;
	string FileName;
	float SimulationTime;
	int QuantumSize;
	int NumProcesses;
	int Lines;
	float TotalLength = 0;
	float AveJobLength;
	float TotalTurnaroundTime = 0;
	float AveTurnaroundTime;
	float TotalWaitTime = 0;
	float AveWaitTime;


	srand(time(NULL));
	cout << "Please enter the file name: " << endl;
	// cin >> FileName;
	FileName = "input.txt";
	fin.open(FileName.c_str());

	if(fin.is_open())
	{

		int Throughput = 0;
		int JobsInSystem = 0;
		int CurrentSystemTime = 0;
		// int JobsSkipped = 0;
		

		cout << "Please enter the desired simulation time (in seconds): ";
		//cin >> SimulationTime;
		SimulationTime = 2.1;
		SimulationTime = SimulationTime * 1000;
		cout << endl;

		cout << "Please enter the desired quantum size (in milliseconds): ";
		//cin >> QuantumSize;
		QuantumSize = 50;
		cout << endl;

		cout << "Please enter the number of processes allowed in the system: ";
		//cin >> NumProcesses;
		NumProcesses = 4;
		cout << endl;

		jobs NextJob;
		fin >> Lines;
		for(int i=0; i<Lines; i++)
		{
			fin >> NextJob.StartTime 
			>> NextJob.PID 
			>> NextJob.ProbIORequest 
			>> NextJob.Length;
			NextJob.TurnaroundTime = 0;
			NextJob.WorkTime = 0;
			NextJob.TotalTime = 0;
			incoming.push(NextJob);

			// cout << NextJob.StartTime << "\t"
			// << NextJob.PID << "\t"
			// << NextJob.ProbIORequest << "\t"
			// << NextJob.Length << "\n";

			fout << NextJob.StartTime << "\t"
			<< NextJob.PID << "\t"
			<< NextJob.ProbIORequest << "\t"
			<< NextJob.Length << "\n";
		}

		for(int j=0; j<NumProcesses; j++)
		{
			ready.push(incoming.front());
			// incoming.front().TotalTime = time(NULL);
			TotalLength = TotalLength + incoming.front().Length;
			// cout << "TotalLength is " << TotalLength << "\n";
			incoming.pop();
		}


		while(CurrentSystemTime <= SimulationTime && (!ready.empty() || !IO.empty()))
		{
			// cout << " CurrentSystemTime is :  " << CurrentSystemTime << "\n";
			fout << " CurrentSystemTime is :  " << CurrentSystemTime << "\n";
			
			CurrentSystemTime = CPU(QuantumSize, ready, IO, Throughput, JobsInSystem, CurrentSystemTime, TotalLength, TotalTurnaroundTime, TotalWaitTime);
			IO_Process(QuantumSize, ready, IO, Throughput, JobsInSystem, TotalTurnaroundTime);
		}


		// JobsSkipped = TotalJobsSkip(incoming);

		JobsInSystem = JobsStillInSystem(ready, IO);

		AveJobLength = TotalLength/float(Throughput + JobsInSystem);
	
		AveTurnaroundTime = TotalTurnaroundTime/float(Throughput + JobsInSystem);

		AveWaitTime = TotalWaitTime/float(Throughput + JobsInSystem);
//.........这里部分代码省略.........
开发者ID:JingxianL,项目名称:345-Operating-System,代码行数:101,代码来源:structV.cpp


示例18: solve

void solve ( )
{
	input();
	w[ex][ey] = 0;
	ac p,q;
	p = a[ex][ey];
	p.step = 0;
	while ( !que.empty() )
		que.pop();
	que.push(p);
	while ( !que.empty() )
	{
		p = que.front();
		que.pop();
		if ( w[p.x][p.y] < p.step )
			continue;
		if ( p.up != 1 && p.x > 0 )
		{
			q = a[p.x-1][p.y];
			if ( p.up == 0 )
				q.step = p.step;
			else
				q.step = p.step+1;
			if ( w[q.x][q.y] > q.step )
			{
				w[q.x][q.y] = q.step;
				que.push(q);
			}
		}
		if ( p.down != 1 && p.x < 200 )
		{
			q = a[p.x+1][p.y];
			if ( p.down == 0 )
				q.step = p.step;
			else
				q.step = p.step+1;
			if ( w[q.x][q.y] > q.step )
			{
				w[q.x][q.y] = q.step;
				que.push(q);
			}
		}
		if ( p.left != 1 && p.y > 0 )
		{
			q = a[p.x][p.y-1];
			if ( p.left == 0 )
				q.step = p.step;
			else
				q.step = p.step+1;
			if ( w[q.x][q.y] > q.step )
			{
				w[q.x][q.y] = q.step;
				que.push(q);
			}
		}
		if ( p.right != 1 && p.y < 200 )
		{
			q = a[p.x][p.y+1];
			if ( p.right == 0 )
				q.step = p.step;
			else
				q.step = p.step+1;
			if ( w[q.x][q.y] > q.step )
			{
				w[q.x][q.y] = q.step;
				que.push(q);
			}
		}
	}
	if ( w[0][0] == inf )
		printf("-1\n");
	else
		printf("%d\n",w[0][0]);
}
开发者ID:fengrenchang86,项目名称:PKU,代码行数:74,代码来源:3510342_RE.cpp


示例19: next_worklist_item

worklist_item next_worklist_item() {
  worklist_item foo = worklist.top();
  worklist.pop();
  return foo;
}
开发者ID:Jornason,项目名称:DieHard,代码行数:5,代码来源:worklist.cpp


示例20: main

int main()
{
    int K,M;
    scanf("%d%d",&K,&M);
    build(1,0,M);
    insert(1,0,M,0,0,0,0,-1);
    
    while (q.size()){
        int L=q.front();
//printf("%d: %d\n",L,dist[L]);
        q.pop();
        
        insert(1,0,M,(L+K)&1,L+K-2*min(L,K),min(L+K-2*max(L+K-M,0),M),dist[L]+1,L);
    }
    
    if (dist[M]==inf){
        puts("-1");
    }else{
        printf("%d\n",dist[M]);
        if (dist[M]<10){
            int len=0,cur=M,path[20];
            while (cur!=0){
                path[len++]=cur;
                cur=pre[cur];
            }
            vector<int> one,zero;
            for (int i=1;i<=M;++i){
                zero.push_back(i);
            }
            while (cur!=M){
                int next=path[--len];
                
                int overlap = (cur+K-next)/2;
                vector<int> out;
                for (int i=0;i<overlap;++i){
                    out.push_back(one.back());
                    one.pop_back();
                }
                for (int i=overlap;i<K;++i){
                    out.push_back(zero.back());
                    zero.pop_back();
                }
                for (int i=0;i<overlap;++i){
                    zero.push_back(out[i]);
                }
                for (int i=overlap;i<K;++i){
                    one.push_back(out[i]);
                }
                
                sort(out.begin(),out.end());
                for (int i=0;i<out.size();++i){
                    if (i) printf(" ");
                    printf("%d",out[i]);
                }
                puts("");
                
                cur=next;
            }
        }
    }
    
    return 0;
}
开发者ID:EC-Ecstasy,项目名称:mithril,代码行数:63,代码来源:H.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ queue_type类代码示例发布时间:2022-05-31
下一篇:
C++ query_type类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap