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


C++ queue类代码示例

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


在下文中一共展示了queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: clear

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

示例10: 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

示例11: empty

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

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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