void* terminator(void* args) { std::cout << "I'll be back!" << std::endl; //couldn't help it MyThreadArgs* mta = (MyThreadArgs*)args; //get the arguments int sock = mta->getMainSock(); //store them locally MyQueue* mq = mta->getQueue(); pthread_t* workers = mta->getWorkerThreads(); int workersAmount = mta->getWorkersAmount(); pthread_t mainThread = mta->getMainThread(); mq->waitForActiveThreads(); //wait for all active firstLineThreads to finish if(close(sock) == -1) //close the main socket perror("close"); for(int i = 0; i < workersAmount; i++) { //join all worker threads mq->signalWorkersForExit(); pthread_join(workers[i], NULL); } pthread_kill(mainThread, SIGRTMIN+1); //signal the main thread to exit pthread_join(mainThread, NULL); //join it delete mq; //delete all allocated memory delete[] workers; delete mta; pthread_detach(pthread_self()); //detach yourself exit(0); //and exit }
//Levelorder void BS_Tree::Levelorder() { TreeNode *temp; MyQueue S; temp = root; if(temp == NULL){ printf("Tree is empty.\n"); } else{ S.AddQ(temp); while(true){ temp = S.DelQ(); if(temp != NULL){ printf("%d ",temp->key); if(temp->left != NULL){ S.AddQ(temp->left); } if(temp->right != NULL){ S.AddQ(temp->right); } } else{ break; } } } }
TEST(D_QueueViaStacksTest, Test1) { std::string output; testing::internal::CaptureStdout(); MyQueue<int> mq; try { mq.enqueue(1); mq.enqueue(2); mq.enqueue(3); mq.enqueue(4); mq.enqueue(5); std::cout << "\n Front element in queue is " << mq.front(); mq.dequeue(); mq.dequeue(); mq.dequeue(); mq.dequeue(); mq.dequeue(); //std::cout << "\n Front element in queue is " << mq.front(); mq.enqueue(6); std::cout << "\n Front element in queue is " << mq.front(); } catch (std::exception e) { std::cout << e.what(); } output = testing::internal::GetCapturedStdout(); EXPECT_EQ(1, 1); }
int main() { MyQueue<int> q; q.add(5); q.add(6); int t = q.remove(); cout << t << endl; return 0; }
int main() { MyQueue q; cout << q.pop() << endl; q.push(1); q.push(10); cout << q.pop() << endl; cout << q.pop() << endl; return 0; }
int main() { MyQueue q; int t, type, data; cin >> t; for (int i = 0; i < t; i++) { cin >> type; if (type == 1) { cin >> data; q.push(data); } else if (type == 2) {
int main() { MyQueue<int> mq; mq.add(1); mq.add(2); mq.remove(); mq.printAll(); debug("Hello world!", ""); return 0; }
int main(int argc,char*argv[]){ MyQueue mq; for(int i=1;i<=5;++i) mq.push(i); for(int i=1;i<=6;++i){ cout << "front: " << mq.front() << endl; cout << "back: " << mq.back() << endl; mq.pop(); } return 0; }
void* workerThread(void* args) { MyQueue* mq = (MyQueue*)args; //get the arguments while(true) //keep running { MyJob* mj = mq->popTop(); //get a job if(mj == NULL) //if it's empty break; //stop running mj->sendFileToClient(); //else, send it to client delete mj; //delete the job } pthread_exit(NULL); //exit }
int main() { MyQueue testQueue; for (int i = 0; i < 10; i++) { testQueue.enqueue(i); std::cout << i << " "; } std::cout << std::endl; for (int i = 0; i < 10; i++) { std::cout << testQueue.dequeue() << " "; } }
int main(int argc, char const *argv[]) { MyQueue<int> q; for(int i = 0; i < 10; i++) { q.push(i); } cout<<q.front()<<" "<<q.rear()<<endl; q.pop(); cout<<q.front()<<" "<<q.rear()<<endl; q.push(11); cout<<q.front()<<" "<<q.rear()<<endl; return 0; }
int main() { MyQueue myqueue = *new MyQueue(); myqueue.enqueue(10); myqueue.enqueue(20); myqueue.enqueue(30); myqueue.enqueue(40); myqueue.enqueue(50); cout<<"NOW SERVING: "<<myqueue.dequeue()<<endl; cout<<"NEXT IN LINE: "<<myqueue.outbox.top()<<endl; return 0; }
int main() { MyQueue q; q.Push(1); q.Push(2); q.Push(3); q.Push(3); while(q.Empty() == false) { int v = q.PopFront(); cout << v << " "; } cout << endl; }
void Output(BinTree<char> &B) { int num; MyQueue<char> Q; B.InOrderInMirror(B.root,Show,Q); int i=0; char arr[DEFAULTSIZE]; B.PreOrder(B.root,arr,i); while (!Q.IsEmpty()) { num=NumCal(arr,Q.getFront()); for (i=1;i<num;i++) cout<<" "; cout<<Q.DeQueue()<<endl; } }
/* This function takes a picture and make from it filled grid. Each element of * grid is image`s pixel. Grid is filled with boolean values. If it is a black * point, it will be marked as true, other - false. */ void imageParsing(string fileName) { string fileAdress = "images/"; fileAdress = fileAdress + fileName; GBufferedImage image; image.load(fileAdress); pixels.resize(image.getWidth(), image.getHeight()); for (int column = 0; column < image.getWidth(); column++) { for (int row = 0; row < image.getHeight(); row++) { if (image.getRGB(column, row) <= GREY) { pixels.set(column, row, true); } else { pixels.set(column, row, false); } } } for (int column = 0; column < pixels.nCols; column++) { for (int row = 0; row < pixels.nRows; row++) { if (pixels.inBounds(column, row) && pixels.get(column, row) == true) { pixels.set(column, row, false); Points blackPoint = makePoint(column, row); checkAllNeighbours.push(blackPoint); detectingSilouettes(pixels); } } } }
int main(){ MyStack<int> a; MyQueue<int> c; a.push(4); a.push(5); cout << a.top() << endl; a.pop(); cout << a.top() << endl; c.enqueue(4); c.enqueue(5); cout << c.front() << endl; c.dequeue(); cout << c.front() << endl; }
void test2() { MyQueue<int> que; for (int i = 0; i < 5; i++) { que.push(i); } //empty() cout << "empty = " << que.empty() << endl; // //pop() que.pop(); que.pop(); que.pop(); //back() int temp_back = que.back(); cout << "temp_back = " << temp_back << endl; //front() int temp_front = que.front(); cout << "temp_front = " << temp_front << endl; }
void Graph<Tv, Te>::BFS(int v, int &clock){ MyQueue<int> Q; //引入辅助队列 status(v) = DISCOVERED; Q.enqueue(v); //初始化起点 while(!Q.empty()){ //在Q变空之前,不断 int v = Q.dequeue(); dTime(v) = ++clock; //取出队首顶点v for(int u = firstNbr(v); -1 < u; u = nextNbr(v, u)) //枚举v的所有邻居 if(UNDISCOVERED == status(u)){ //尚未被发现,则 status(u) = DISCOVERED; //设置为已发现 Q.enqueue(u); //并且将该顶点入队 type(v, u) = TREE; parent(u) = v; //引入树边拓展支撑树 }else{ type(v, u) = CROSS; //将(v,u)归类于跨边 } status(v) = VISITED; //至此,当前节点访问完毕 } }
int C3Q5() { MyQueue mq; int pushArray[3] = { 10, 6, 3 }; int pullArray[3] = { 8, 4, 7 }; for (int i = 0; i < 3; i++) { for (int j = 0; j < pushArray[i]; j++) { mq.push(j); //printf("push %d into queue", j); } for (int j = 0; j < pullArray[i]; j++) { printf("pull %d out\n", mq.pull()); } } return 0; }
/* Concept - - we will give a vertex, and in this function we are going to calculate the diatance of all other connected node, from this vertex. Algo - - First set the distance array to -1, for all the vertex. */ void ShortestPath(int vertex) { initializeArray(); m_distance[vertex] = 0; // distance to self is 0 MyQueue<char> q; q.enQueue(m_graphLookup[vertex]); char vertexTemp; while (!q.isEmpty()) { vertexTemp = q.deQueue(); for (int index = 0; index < m_vertex; ++index) { //if (m_matrix[vertex][index]) //{ // m_distance[index] = //} } } }
int main (char *argv[], int argc) { MyQueue q; q.push(1); q.push(2); q.push(3); cout << q.front() << endl; cout << q.back() << endl; q.pop(); cout << q.front() << endl; cout << q.back() << endl; return 0; }
int main(int argc, char** argv) { MyQueue<int> myQ; myQ.enqueue(1); myQ.enqueue(2); myQ.enqueue(3); myQ.enqueue(4); while (myQ.size() > 2) { cout << "Front of MyQueue object: " << myQ.front() << endl; myQ.dequeue(); } myQ.enqueue(5); myQ.enqueue(6); while (myQ.size() > 0) { cout << "Front of MyQueue object: " << myQ.front() << endl; myQ.dequeue(); } return 0; }
/* This function takes filled grid with boolean values. Black points are marked * as true, other - as false. If number of neighbour black points more than * const MIN_SILOUETTES_SIZE, such area is marked is silouette. * Function returns the number of silouettes. */ void detectingSilouettes(Grid<bool> &pixels) { int countBlackPoints; while (!checkAllNeighbours.empty()) { Points buffer = checkAllNeighbours.front(); checkAllNeighbours.pop(); for (int x = buffer.column - 1; x <= buffer.column + 1; x++) { for (int y = buffer.row - 1; y <= buffer.row + 1; y++) { if (pixels.inBounds(x, y) && pixels.get(x, y) == true) { countBlackPoints++; Points blackPoint = makePoint(x, y); pixels.set(x, y, false); checkAllNeighbours.push(blackPoint); } } } } if (countBlackPoints >= MIN_SILOUETTES_SIZE) { countSilouettes++; countBlackPoints = 0; } }
/* * Repaint silhouette in color of background * * @param point Extreme point of silhouette * @param imageMatrix 2d array that contains color's * @param width The width of the image * @param height The height of the image * @param backgroundColor Variable that indicate background color */ void SilCounter::fillSilhouette(QPoint &point, int **imageMatrix, int width, int height, int backgroundColor){ // queue that store all point neighbours, with silhouette color MyQueue<QPoint> queueOfPoints; // repaint point in background color to prevent it from re-adding to the queue from cycle imageMatrix[point.y()][point.x()] = backgroundColor; queueOfPoints.push(point);\ // walk throw all point neigbours with silhouette color while(queueOfPoints.size()){ // temporary variable for poin from queue QPoint temp = queueOfPoints.front(); int x = temp.x(); int y = temp.y(); queueOfPoints.pop();\ // walk throw all point neigbours with silhouette color repaint them and adding to the queue for(int i = -1; i <= 1; i++){ for(int j = -1; j <= 1; j++){ if( (0 <= x + i) && (x + i < width) && (0 <= y + j) && (y + j < height) && (imageMatrix[y + j][x + i] != backgroundColor)){ imageMatrix[y + j][x + i] = backgroundColor; queueOfPoints.push(QPoint(x + i,y + j)); } } } } }
//Insert void BS_Tree::Insert(int key) { int i; TreeNode *temp,*newNode; MyQueue S; newNode = (TreeNode*) malloc(sizeof(TreeNode)); newNode->key = key; newNode->right = NULL; newNode->left = NULL; temp = root; //root is empty if(root == NULL){ root = newNode; } //root isn't empty else{ S.AddQ(temp); while(true){ temp = S.DelQ(); //LeftNode is empty if(temp->left == NULL){ temp->left = newNode; break; } //RightNode is empty else if(temp->right == NULL){ temp->right = newNode; break; } else{ S.AddQ(temp->right); S.AddQ(temp->left); continue; } } } }
int main() { MyQueue<int> que; que.push(1); que.push(2); que.push(3); que.push(4); while(que.size() != 0) { cout<<que.pop()<<" "; } que.push(5); que.push(6); while(que.size() != 0) { cout<<que.pop()<<" "; } cout<<endl; que.pop(); return 0; }
int main() { MyQueue *q; int n, m; int i; char s[20]; int val; while (scanf("%d%d", &n, &m) == 2) { q = new MyQueue(m); for (i = 0; i < n; ++i) { scanf("%s", s); if (strcmp(s, "Push") == 0) { scanf("%d", &val); if (q->full()) { printf("failed\n"); } else { q->push(val); } } else if (strcmp(s, "Pop") == 0) { if (q->empty()) { printf("failed\n"); } else { q->pop(); } } else if (strcmp(s, "Query") == 0) { scanf("%d", &val); if (val < 1 || val > q->size()) { printf("failed\n"); } else { printf("%d\n", q->front(val)); } } else if (strcmp(s, "Isempty") == 0) { printf(q->empty() ? "yes\n" : "no\n"); } else if (strcmp(s, "Isfull") == 0) { printf(q->full() ? "yes\n" : "no\n"); } } delete q; } return 0; }
int main(void) { MyQueue<int> list; list.enqueue(1); list.enqueue(2); cout << "Size = " << list.size() << endl; cout << "Dequeue => " << list.dequeue() << endl; cout << "Peek => " << list.peek() << endl; list.clear(); if (list.isEmpty()) list.enqueue(3); return 0; }
int main(){ MyQueue<int> q; for(int i=0; i<10; ++i){ q.push(i); } q.pop(); q.pop(); q.push(10); cout<< q.sintop() << ' ' << q.top() << endl; return 0; }
int main(int argc, char *argv[]) { MyQueue mq; mq.Enqueue(1); mq.Enqueue(2); mq.Enqueue(3); mq.Dequeue(); mq.Enqueue(4); mq.PrintQueue(); system("PAUSE"); return EXIT_SUCCESS; }