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(); }
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; }
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(); }
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; }
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; }
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; }
TEST_F(TestDownloader, DownloaderShouldPushDataToQueue) { const std::string data(CHUNK_SIZE, '$'); FakeSource src(data, CHUNK_DELAY); Queue q; Downloader dl(src, q); dl.Start(); dl.Wait(); ASSERT_EQ(MakeChunk(data), q.Pop(CHUNK_SIZE)); }
TEST_F(TestDownloader, CancelShouldStopDownloader) { const std::string data(CHUNK_SIZE, '$'); FakeSource src(data, CHUNK_DELAY, CHUNK_NUMBER); Queue q; Downloader dl(src, q); dl.Start(); usleep(CHUNK_DELAY); dl.Cancel(); ASSERT_EQ(MakeChunk(data), q.Pop(CHUNK_SIZE * CHUNK_NUMBER)); }
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; }
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()); }
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; }
//获取消息队列消息 void proc(void *arg) { HWND hMain = (HWND)arg; USE_JSONCODER_DOC(document); while(1) { Sleep(1); CAutoLock lock(&g_TGetLock); char *msg = NULL; try { msg = reinterpret_cast<char *>(msg_queue.Pop()); //msg = (&doublebuffer_queue)->Popup(); if(!msg) { continue; } } catch(...){ //Log("proc : msg_queue.Pop() fialed."); } #ifdef DEBUG_MODE std::cout << msg << std::endl; #endif //解码 LOAD_JSONCODER_STR(document, msg); JsonCoder jc_decoder; if(!jc_decoder.CheckPacket(document)) { //cout << "error packet" << endl; PostMessage(hMain, WM_ERRORPCK, 0, 0); continue; } //获取消息 uint32 cmd = jc_decoder.GetInt(JC_KEY::JC_MSGTYPE, document); //服务端发送过来的回应包 if(cmd == MESSAGE_TYPE::cmdLoginRep) { //返回的客户列表 std::string user_list = jc_decoder.GetString(JC_KEY::JC_USERLISTREP, document); //上线提示 std::string onlineUser = jc_decoder.GetString(JC_KEY::JC_ONLINEREP, document); //发送上线提醒消息 std::string *olUser = new std::string(onlineUser); PostMessage(hMain, WM_ONLINEWARN, (WPARAM)olUser, 0); #ifdef DEBUG_MODE cout << "user_list" << user_list << endl; #endif //发送列表消息 std::string *uList = new std::string(user_list); //上线的用户提示 std::string *warn = new std::string(onlineUser); PostMessage(hMain, WM_UPDATELIST, (WPARAM)uList, (LPARAM)warn); } else if(cmd == MESSAGE_TYPE::cmdLogoutRep) { //客户端离线提示 std::string logoutUser = jc_decoder.GetString(JC_KEY::JC_LOGOUTUSER, document); //列表删除 ClientMap::iterator ite = cmap.begin(); ite = cmap.find(logoutUser); if(ite != cmap.end()) { cmap.erase(ite); } std::string *ss = new std::string(logoutUser); PostMessage(hMain, WM_DELUSERLIST, (WPARAM)ss, 0); } else if(cmd == MESSAGE_TYPE::cmdPublicMsgRep) { //发送者id std::string user_identify = jc_decoder.GetString(JC_KEY::JC_IDENTIFY, document); //谁发送的 std::string sender = jc_decoder.GetString(JC_KEY::JC_SENDER, document); //发送了什么 std::string pubmsg = jc_decoder.GetString(JC_KEY::JC_PUBMSG, document); //发送时间 std::string pubtime = jc_decoder.GetString(JC_KEY::JC_PUBTIME, document); if(strcmp(user_identify.c_str(), g_Identify.c_str()) != 0) { std::wstring tmp = PublicTool::string2wstring(sender); tmp.append(STR_OTHER_SAY); tmp.append(PublicTool::string2wstring(pubmsg)); tmp.append(L"["); tmp.append(PublicTool::string2wstring(pubtime)); tmp.append(L"]"); std::wstring *ss = new std::wstring(tmp); PostMessage(hMain, WM_PUBMSG, (WPARAM)ss, 0); } } //内存归还到内存池 MsgPool.Release(msg); } }
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; }