Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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();

}
Exemplo n.º 3
0
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:"******"\nInserting User:"******" 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;
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
void flext_base::AddIdle()
{
    MsgBundle *m = MsgBundle::New();
    m->Idle(const_cast<flext_base *>(this));
    // send over queue
    queue.Push(m);
}
Exemplo n.º 7
0
void flext_base::AddIdle(bool (*idlefun)(int argc,const t_atom *argv),int argc,const t_atom *argv)
{
    MsgBundle *m = MsgBundle::New();
    m->Idle(idlefun,argc,argv);
    // send over queue
    queue.Push(m);
}
Exemplo n.º 8
0
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();
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
0
Arquivo: tree.hpp Projeto: mboghiu/try
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());
}
Exemplo n.º 14
0
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;
}
Exemplo n.º 15
0
//读取信息到队列
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.");
		}
    }
}
Exemplo n.º 16
0
static bool QWork(bool syslock,flext_base *flushobj = NULL)
{
    // 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.
    flext::MsgBundle *q;
    if((q = queue.Get()) == NULL) 
        return false;
    else if(q->Send()) {
        if(!flushobj || !q->BelongsTo(flushobj))
            queue.Push(q);  // remember messages to be processed again
        else
            flext::MsgBundle::Free(q);
        return true;
    }
    else {
        flext::MsgBundle::Free(q);
        return false;
    }
}
Exemplo n.º 17
0
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;
}
int main()
{
	Queue<string> myStringQueue;

	myStringQueue.Push( "Hello" );
	myStringQueue.Push( "Saluton" );
	myStringQueue.Push( "Konnichiwa" );
	myStringQueue.Push( "Bonjour" );
	myStringQueue.Push( "Hola" );

	Stack<string> myStringStack;

	myStringStack.Push( "Hello" );
	myStringStack.Push( "Saluton" );
	myStringStack.Push( "Konnichiwa" );
	myStringStack.Push( "Bonjour" );
	myStringStack.Push( "Hola" );

	int count = 0;
	while ( myStringStack.GetSize() != 0 )
	{
		cout << "Loop " << count << endl;
		cout << "\t Stack: " << myStringStack.Top() << endl;
		cout << "\t Queue: " << myStringQueue.Front() << endl;
		cout << endl;
		count++;

		myStringStack.Pop();
		myStringQueue.Pop();
	}

	cout << "Press a key to continue..." << endl;
	cin.get();

	Queue<int> myIntQueue;

	myIntQueue.Push( 1 );
	myIntQueue.Push( 1 );
	myIntQueue.Push( 2 );
	myIntQueue.Push( 3 );
	myIntQueue.Push( 5 );

	Stack<int> myIntStack;

	myIntStack.Push( 1 );
	myIntStack.Push( 1 );
	myIntStack.Push( 2 );
	myIntStack.Push( 3 );
	myIntStack.Push( 5 );

	count = 0;
	while ( myIntStack.GetSize() != 0 )
	{
		cout << "Loop " << count << endl;
		cout << "\t Stack: " << myIntStack.Top() << endl;
		cout << "\t Queue: " << myIntQueue.Front() << endl;
		cout << endl;
		count++;

		myIntStack.Pop();
		myIntQueue.Pop();
	}

	cout << "Press a key to exit..." << endl;
	cin.get();

	return 0;
}
Exemplo n.º 19
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   Queue * queue;
   string fname = "/cpp_queue_status";
   string qname = fname + "/test";
   const char * data1 = "My Data1";
   const char * data2 = "My Data2";
   const char * data3 = "My Data3";
   psoObjStatus status;
   psoObjectDefinition queueDef = { PSO_QUEUE, 0, 0, 0 };
   psoFieldDefinition fields[1] = {
      { "Field_1", PSO_VARCHAR, {10} }
   };

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   try {
      session.Init();
      session.CreateFolder( fname );

      DataDefinition dataDefObj( session, 
                                 "cpp_queue_status",
                                 PSO_DEF_PHOTON_ODBC_SIMPLE,
                                 (unsigned char *)fields,
                                 sizeof(psoFieldDefinition) );
      session.CreateQueue( qname,
                           queueDef,
                           dataDefObj );
      queue = new Queue( session, qname );
      queue->Push( data1, strlen(data1) );
      queue->Push( data2, strlen(data2) );
      queue->Push( data3, strlen(data3) );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // End of invalid args. This call should succeed.
   try {
      queue->Status( status );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   if ( status.numDataItem != 3 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   if ( status.numBlocks != 1 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   if ( status.numBlockGroup != 1 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   if ( status.freeBytes == 0 || status.freeBytes >=PSON_BLOCK_SIZE ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }

   return 0;
}
Exemplo n.º 20
0
void flext::ToQueueMsg(MsgBundle *m)
{
    queue.Push(m);
}
Exemplo n.º 21
0
void flext_base::ToQueueBang(int o) const 
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o);
    queue.Push(m);
}
Exemplo n.º 22
0
void flext_base::ToQueueInt(int o,int f) const
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o,f);
    queue.Push(m);
}
Exemplo n.º 23
0
void TestFunc()
{
  Test test;

  int v = 5;

  Queue queue;

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetParamStatic,      &Test::SetReferenceStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetParamStatic,      &Test::SetReferenceStatic), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetReferenceStatic,  &Test::SetValueStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetReferenceStatic,  &Test::SetValueStatic), v ));

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetValueStatic,      &Test::SetReferenceStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetValueStatic,      &Test::SetReferenceStatic), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetParamStatic,      &Test::SetValueStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetParamStatic,      &Test::SetValueStatic), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetReferenceStatic,  &Test::SetReferenceStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetReferenceStatic,  &Test::SetReferenceStatic), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetValueStatic,      &Test::SetValueStatic) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::StaticProperty<int> (&Test::GetValueStatic,      &Test::SetValueStatic), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetParam,      &Test::SetReference) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetParam,      &Test::SetReference), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetReference,  &Test::SetValue) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetReference,  &Test::SetValue), v ));

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetValue,      &Test::SetReference) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetValue,      &Test::SetReference), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetParam,      &Test::SetValue) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetParam,      &Test::SetValue), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetReference,  &Test::SetReference) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetReference,  &Test::SetReference), v ) );

  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetValue,      &Test::SetValue) ) );
  queue.Push( new PropertyCommand<int> ( new Helium::MemberProperty<Test, int> (&test,   &Test::GetValue,      &Test::SetValue), v ) );
}
Exemplo n.º 24
0
void flext_base::ToQueueSymbol(int o,const t_symbol *s) const
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o,s);
    queue.Push(m);
}
Exemplo n.º 25
0
void MatrixGraph::bfs()
{
	bool* visit = new bool[size];
	memset(visit, false, size);
	Queue<int> queue;

	int visited = 0;	//	0번 vertex부터 출발
	visit[visited] = true;

	queue.Push(visited);

	int connecctComponent = 1;	//	연결요소 개수

	IoHandler ioh;
	ioh.putString("인접행렬 + BFS");
	ioh.putNewLine();

	for (int i = 0; i < size; i++)
	{

		//	다음 vertex로 넘어왔는데 false면 연결요소가 끊어진 것
		if (visit[i] == false)
		{
			ioh.putString("연결요소");
			ioh.putInteger(connecctComponent++);
			ioh.putString(" - ");

			while (1)
			{	//	출력
				ioh.printConnectedComponent(queue.Front());
				queue.Pop();

				if (queue.isEmpty() == true)
				{
					break;
				}
			}
			ioh.putNewLine();
		}

		if (visit[i] == false)
		{
			visit[i] = true;
			queue.Push(i);
		}


		for (int j = 0; j < size; j++)
		{
			if (adjMatrix[i][j] == true)
			{
				if (visit[j] == false)
				{
					visit[j] = true;
					queue.Push(j);
				}
			}
		}
	}	//	for end

	if (queue.isEmpty() == false)
	{
		ioh.putString("연결요소");
		ioh.putInteger(connecctComponent++);
		ioh.putString(" - ");

		while (1)
		{	//	출력
			ioh.printConnectedComponent(queue.Front());
			queue.Pop();

			if (queue.isEmpty() == true)
			{
				break;
			}
		}
		ioh.putNewLine();
	}

	return;
}
Exemplo n.º 26
0
void flext_base::ToQueueAtom(int o,const t_atom &at) const
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o,at);
    queue.Push(m);
}
Exemplo n.º 27
0
void flext_base::ToQueueList(int o,int argc,const t_atom *argv) const
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o,argc,argv);
    queue.Push(m);
}
Exemplo n.º 28
0
void flext_base::ToQueueAnything(int o,const t_symbol *s,int argc,const t_atom *argv) const
{
    MsgBundle *m = MsgBundle::New();
    m->Add(const_cast<flext_base *>(this),o,s,argc,argv);
    queue.Push(m);
}