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


C++ Queue::Push方法代码示例

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


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

示例1: main

int main()
{
	Queue qu;
	char* str1 = "push1";
	char* str2 = "push2";
	char* str3 = "push3";
	char* str4 = "push4";
	char* str5 = "push5";

	//Push
	qu.Push(str1);
	qu.Push(str2);
	qu.Push(str3);
	qu.Push(str4);
	qu.Push(str5);

	//Pop
#if 1
	int count = qu.GetSize();
	cout << "size : " << count << endl;
	for(int i=0; i<count; i++){
		cout << (char*)qu.Pop() << endl;
	}
#else
	qu.ShowAllData();
#endif

	return 0;
}
开发者ID:kym4335,项目名称:ymkim_util,代码行数:29,代码来源:Queue.cpp

示例2: main

void main()
{
	Queue queue;

	queue.Push(Point(99,55),0);
	queue.Push(Point(88,55),1);
	queue.Push(Point(77,55),2);
	queue.Push(Point(66,55),1);
	queue.Push(Point(55,55),2);
	queue.Push(Point(44,55),4);
	queue.Push(Point(33,55),3);

	Point p = queue.Pop();
	p = queue.Pick();

	queue.Push(Point(22,55),5);

	p = queue.Pick();
	p = queue.Pop();
	p = queue.Pop();
	p = queue.Pop();
	p = queue.Pop();
	p = queue.Pop();
	p = queue.Pop();

}
开发者ID:NazarDemchuck,项目名称:cpp-lessons,代码行数:26,代码来源:main.cpp

示例3: main

int main(int argc,char *argv[])
{
    srand(time(NULL));
    signal(SIGTERM,SIGTERMHandler);

	GLOBAL_PROCESS_IDS *GPI = (GLOBAL_PROCESS_IDS*)
								GetSHM(sizeof(GLOBAL_PROCESS_IDS),GLOBAL_MEM);

    //Put values in global shared memory for other process to see
    GPI->CarUnload = getpid();
    
    Queue *Q = (Queue *) GetSHM(SHMSIZE,TOURISTS_Q);
    
    int size = GPI->CarCapacity*sizeof(TouristInfo);
    Queue *CarTable = (Queue *) GetSHM(size+sizeof(Queue),CAR_TABLE);

    Queue *TouristStatus = (Queue *) GetSHM(SHMSIZE,TOURISTS_STAT);
    TouristStatus->Queue_INIT(SHMSIZE-sizeof(Queue),TOURISTS_STAT);

    SignalHandler::WaitForSignal(SIGCONT);
    
    while(flag)
    {            
        CarTable->Lock();
        cout<<"Locked";
        while(CarTable->Size() > 0)
        {
            sleep(1);
            int elem = CarTable->Pop(true);
            kill(elem,SIGCONT);
            cout<<RED<<"\nRemoving User:"<<elem<<DEFAULT<<flush;
            
            //if(false)
            if( R(100) < GPI->Probabilty)
            {
                Q->Push(elem);
                kill(elem,SIGCONT);
                cout<<GREEN<<"\nInserting User:"<<elem<<" back to Queue."<<DEFAULT<<flush;
            }
            else kill(elem,SIGTERM);
            TouristStatus->Push(elem);    
        }    
        
        CarTable->Unlock();
        
        //sleep(2);//simulate working....
        GPI->CarMode = CARMODES::READY;
        cout<<GREEN<<"\nCarMode READY\n"<<DEFAULT<<flush;
        SignalHandler::WaitForSignal(SIGCONT);
    }
    cout<<RED<<endl<<argv[0]<<" Exiting..\n"<<DEFAULT<<flush;
    
    //shmdt(Q);
	//shmdt(GPI);
    //shmdt(CarTable);
    //shmdt(TouristStatus);
    
    return 0;
}
开发者ID:montyc008,项目名称:LabAssignments,代码行数:59,代码来源:CarUnload.cpp

示例4: MakeQueue

Queue* QueueToken::MakeQueue()
{
	Queue* ret = new Queue;
	//split at ",", ignoring strings
	
	//first two chars are "()", ignore.
	std::string expression = Read().substr(2);
	int i;
	for (i = 0; i < expression.size(); i++) 
	{

		if (expression[i] == '\'' || expression[i] == '\"')
		{
			i += Parse::ParseStringLiteral(expression.substr(i)).size();
			std::string test = expression.substr(i);
		}
		else if (expression[i] == '(')
		{
			i += Parse::ParseToMatchingParen(expression.substr(i), '(', ')').length() + 2;
			std::string test = expression.substr(i);
		}
		if (i < expression.size() && (expression[i] == ',' || expression[i] == ';'))
		{

			std::string tmp = expression.substr(0, i);
			Tokenizer tokenizer(tmp);

			Evaluator eval(tokenizer.Tokenize());

			ret->Push(eval.Evaluate()->clone());

			expression = expression.substr(i + 1);

			i = 0;

		}

	}

	Tokenizer tokenizer(expression);
	auto tokens = tokenizer.Tokenize();
	Evaluator eval(tokens);

	for (size_t i = 0; i < tokens.size(); i++)
	{
		delete tokens[i];
	}
	tokens.clear();

	Type* evaluated = eval.Evaluate();
	
	if (evaluated != nullptr)
		ret->Push(evaluated->clone());

	return ret;
}
开发者ID:zsebastian,项目名称:sml_old,代码行数:56,代码来源:QueueToken.cpp

示例5: main

int main()
{
	Queue<int> q;
	q.Push(1);
	q.Push(2);
	q.Push(3);
	int h=q.Front();
	cout<<h<<endl;
	h=q.Front();
	cout<<h<<endl;
}
开发者ID:coverxiaoeye,项目名称:offer-1,代码行数:11,代码来源:7_stackToQueue.cpp

示例6: AddIdle

void flext_base::AddIdle()
{
    MsgBundle *m = MsgBundle::New();
    m->Idle(const_cast<flext_base *>(this));
    // send over queue
    queue.Push(m);
}
开发者ID:EQ4,项目名称:IntegraLive,代码行数:7,代码来源:flqueue.cpp

示例7: TestQueue

void TestQueue()
{
	Queue<int> q;
	q.Push(1);
	q.Push(2);
	q.Push(3);
	q.Push(4);

	q.Print();

	q.Pop();
	q.Pop();
	q.Pop();

	q.Print();
}
开发者ID:zhouxumeng213,项目名称:data-structure,代码行数:16,代码来源:queue.cpp

示例8: menuQueue

void  menuQueue()
{
	Queue *queue = new Queue;
	char c;
	do
	{
		printf("1: Push\n");
		printf("2: Pop\n");
		printf("3: IsEmpty\n");
		printf("\nEsc: Exit\n");
		c = getch();
		switch(c)
		{
		case '1': 
			cout << "Push:";
			int val;
			cin >> val;
			queue->Push(val);
			cout << endl; break;
		case '2': 
			cout << "Pop:";
			int v;
			v = queue->Pop();
			cout << v << endl; break;
		case '3': 
			cout << "IsEmpty:";
			bool flag = queue->IsEmpty();
			cout << ( flag == true ? "true" : "false") << endl; break;
		}
	} while(c != 27);
	delete queue;
}
开发者ID:klyuchnikov,项目名称:LabsThreeSemestrsEVM,代码行数:32,代码来源:Main.cpp

示例9: QueueForward

bool flext::QueueForward(const t_symbol *recv,const t_symbol *s,int argc,const t_atom *argv)
{
    MsgBundle *m = MsgBundle::New();
    m->Add(recv,s,argc,argv);
    // send over queue
    queue.Push(m);
    return true;
}
开发者ID:EQ4,项目名称:IntegraLive,代码行数:8,代码来源:flqueue.cpp

示例10: Test

void Test()
{
	Queue<int> q;
	q.Push(1);
	q.Push(2);
	q.Push(3);
	q.Push(4);
	cout<<q.Front()<<endl<<endl;
	cout<<q.Back()<<endl<<endl;
	cout<<q.Empty()<<endl<<endl;
	cout<<q.Size()<<endl<<endl;
	q.Pop();
	q.Pop();
	q.Pop();
	q.Pop();
	q.Pop();
	cout<<endl<<q.Empty()<<endl<<endl;
}
开发者ID:Doo66,项目名称:Data-Structure,代码行数:18,代码来源:queue.cpp

示例11: QWork

static bool QWork(bool syslock,flext_base *flushobj = NULL)
{
    Queue newmsgs;
    flext::MsgBundle *q;

#if 0
    static int counter = 0;
    fprintf(stderr,"QWORK %i\n",counter++);
#endif

    for(;;) {
        // Since qcnt can only be increased from any other function than QWork
        // qc will be a minimum guaranteed number of present queue elements.
        // On the other hand, if new queue elements are added by the methods called
        // in the loop, these will be sent in the next tick to avoid recursion overflow.
        if(!queue.Avail()) break;

    #if FLEXT_QMODE == 2
        if(syslock) flext::Lock();
    #endif

        while((q = queue.Get()) != NULL) {
            if(q->Send())
                newmsgs.Push(q);  // remember messages to be processed again
            else
                flext::MsgBundle::Free(q);
        }

    #if FLEXT_QMODE == 2
        if(syslock) flext::Unlock();
    #endif

    }

    // enqueue messages that have to be processed again
    while((q = newmsgs.Get()) != NULL)
        if(!flushobj || !q->BelongsTo(flushobj))
            queue.Push(q);
        else
            flext::MsgBundle::Free(q);

    return queue.Avail();
}
开发者ID:EQ4,项目名称:IntegraLive,代码行数:43,代码来源:flqueue.cpp

示例12: move

std::string bt<T>::BFTraverse() const
{
    if (_tree == nullptr)
        return "";

    std::stringstream ss;

    Queue<Node> queue;
    queue.Push(*_tree);

    while (queue.Peek() != nullptr)
    {
        auto front = queue.Pop()->m_data;

        ss << front.data << "|";

        if (front.left != nullptr)
            queue.Push(*front.left);
        if (front.right != nullptr)
            queue.Push(*front.right);
    }

    return std::move(ss.str());
}
开发者ID:mboghiu,项目名称:try,代码行数:24,代码来源:tree.hpp

示例13: main

int main()
{
    Queue<int> numStack;

    cout << endl << "PUSH" << endl;
    for ( int i = 0; i < 5; i++ )
    {
        numStack.Push( i * 3 );
    }

    cout << endl << "POP" << endl;
    while ( numStack.Size() != 0 )
    {
        numStack.Pop();
    }

    return 0;
}
开发者ID:Rachels-Courses,项目名称:CPP-Course,代码行数:18,代码来源:main.cpp

示例14: read_func

//读取信息到队列
void read_func(void *arg)
{ 
	while(1)
    {
        Sleep(1);
		CAutoLock lock(&g_TReadLock);
		std::string rcv("");
		try
		{
			rcv = sClient->ReceiveBytes();
		}
		catch(...)
		{
			//Log("read_func : MsClient->ReceiveBytes() fialed.");
			continue;
		}
        if(strlen(rcv.c_str()) == 0)
        {
            continue;
        }
	#ifdef  DEBUG_MODE
		std::cout << "read_func : " << rcv << std::endl;
	#endif
		char *data_buff = NULL;
		data_buff = reinterpret_cast<char *>(MsgPool.Get());
		//已解决bug1:如果不对其内存memset清0,,内存的当前值就会覆盖上次的(memcpy),
		//可能导致会有"垃圾尾巴"(例如上次内容为:12345,这次的期望内容是:abc,
		//最后在内存的值会变为:abc45,忘注意,这个和内存池本来的实现有关。
		if(data_buff)
		{
			memset(data_buff, 0, DATA_BLOCK_LEN);
			memcpy(data_buff, rcv.c_str(), strlen(rcv.c_str()));
			msg_queue.Push(data_buff);
			//(&doublebuffer_queue)->Push(data_buff);
		}
		else
		{
			//Log("read_func : MsgPool.Get() fialed.");
		}
    }
}
开发者ID:zeekerzhang,项目名称:chat_demo,代码行数:42,代码来源:demoDlg.cpp

示例15: _tmain

int _tmain(int argc, _TCHAR* argv[])
{
	Queue<int> q;

	for (int i = 0; i < 10; ++i)
	{
		int* p = new int(i);
		q.Push(p);
	}
	std::cout << "Queue's size: " << q.Size() << std::endl;

	int* p;
	for (int i = 0; i < 10; ++i)
	{
		bool ret = q.Pop(p);
		if (ret)
		{
			std::cout << *p << std::endl;
		}
	}

	//q.print();
	return 0;
}
开发者ID:LeftThink,项目名称:CodeTricks,代码行数:24,代码来源:LockFreeQueue.cpp


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