int main( ) { Queue Q; int i; Q = CreateQueue( 12 ); FAIL_ON_NULL(Q->data) i=0; for( i = 0; i < 10; i++ ) Enqueue( i, Q ); while( !IsEmpty( Q ) ) { printf( "%d\n", Front( Q ) ); Dequeue( Q ); } for( i = 0; i < 20; i++ ) Enqueue( i, Q ); while( !IsEmpty( Q ) ) { printf( "%d\n", Front( Q ) ); Dequeue( Q ); } DisposeQueue( Q ); return 0; }
void DancePartner(Person dancer[],int num) { //结构数组dancer中存放跳舞的男女,num是跳舞的人数。 int i; Person p; CirQueue Mdancers,Fdancers; Initial(&Mdancers);//男士队列初始化 Initial(&Fdancers);//女士队列初始化 for(i=0; i<num; i++) { //依次将跳舞者依其性别入队 p=dancer[i]; if(p.sex=='F') EnQueue(&Fdancers,p); //排入女队 else EnQueue(&Mdancers,p); //排入男队 } printf("舞队是:\n"); while(!IsEmpty(&Fdancers)&&!IsEmpty(&Mdancers)) { //依次输入男女舞伴名 p=DeQueue(&Fdancers); //女士出队 printf("%s ",p.name);//打印出队女士名 p=DeQueue(&Mdancers); //男士出队 printf("%s\n",p.name); //打印出队男士名 } if(!IsEmpty(&Fdancers)) { //输出女士剩余人数及队头女士的名字 printf("还有 %d 个女士等下一轮.\n",Fdancers.count); p=Front(&Fdancers); //取队头 printf("%s will be the first to get a partner. \n",p.name); } else if(!IsEmpty(&Mdancers)) { //输出男队剩余人数及队头者名字 printf("还有%d 个男士等下一轮.\n",Mdancers.count); p=Front(&Mdancers); printf("%s will be the first to get a partner.\n",p.name); } }
//] //[eglplus_example_hello_world_2 int main(void) { if(eglplus::__LibEGL::HasClientExtensions()) { std::cout << "Client extensions:" << std::endl; for(auto r=eglplus::__LibEGL::ClientExtensions(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; } else std::cout << "No client extensions." << std::endl; eglplus::__Display display; eglplus::__LibEGL egl(display); std::cout << "Vendor: " << egl.Vendor() << std::endl; std::cout << "Version: " << egl.Version() << std::endl; std::cout << "Client APIs:" << std::endl; for(auto r=egl.ClientAPIs(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; std::cout << "Extensions:" << std::endl; for(auto r=egl.Extensions(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; return 0; }//]
void DescriptorAllocator::FreeTemporaryAllocations() { while (Size(PendingTemporaryBlocks)) { if (IsFenceCompleted(Blocks[Front(PendingTemporaryBlocks)].fence)) { auto index = Front(PendingTemporaryBlocks); PopFront(PendingTemporaryBlocks); PushBack(TemporaryBlocks, index); Blocks[index].fence = {}; Blocks[index].next_allocation_offset = 0; } else { break; } } CurrentTemporaryBlockIndex = 0; }
int main() { Queue TestQueue = CreateQueue(10); cout << "Begin test of queue " << endl; for (int i = 0, n = 1; i < 10; i++, n *= 2) { cout << i + 1 << "> Enqueue : " << n<<endl; Enqueue(n, TestQueue); } PrintQueue(TestQueue); cout << "Is Full ? " << IsFull(TestQueue)<<endl; for (int i = 0; i < 5; i++) { cout << i + 1 << " >Dequeue :" << Front(TestQueue) << endl; Dequeue(TestQueue); } PrintQueue(TestQueue); cout << "Front and dequeue: " << FrontAndDequeue(TestQueue)<<endl; cout << "Now add more data to test the cicular array..." << endl; for (int i = 0; i < 5; i++) { cout << i + 1 << "> Enqueue : " << i << endl; Enqueue(i, TestQueue); } PrintQueue(TestQueue); cout << "Now make the queue empty..."; MakeEmpty(TestQueue); cout << "Is Empty ? "<<IsEmpty(TestQueue)<<endl; cout << "Now dipose the queue!" << endl; DisposeQueue(TestQueue); cout << "Test Succeed!" << endl << "Good bye!"<<endl; getchar(); }
bool nuiPath::IsClosed() const { if (GetCount() < 3) return false; return Back() == Front(); }
int findBottomLeftValue(TreeNode* root) { Trique*q=zCreateQueue(1000);; Queue*level=CreateQueue(1000); zEnqueue(q,root); Enqueue(level,0); int m=0; while(q->NumElements){ TreeNode *r = zFront(q); zDequeue(q); int l = Front(level); Dequeue(level); if(r->left) { zEnqueue(q,r->left); Enqueue(level,l+1); } if(r->right){ zEnqueue(q,r->right); Enqueue(level,l+1); } if(l > m){ m = l; root = r; } } return root->val; }
int main() { SeQueue Q; int data = 3, value; //0. Init InitQueue(Q); PrintQueue(Q); //1. Enter Queue printf("\n"); PrintQueue(Q); printf("EnQueue = %d\n", data); EnQueue(Q, data); PrintQueue(Q); //2. DeQueue printf("\n"); PrintQueue(Q); value = Front(Q); DeQueue(Q); printf("DeQueue value = %d\n", value); PrintQueue(Q); //3. Clear printf("\n"); PrintQueue(Q); printf("Clear Queue\n"); ClearQueue(Q); PrintQueue(Q); return 0; }
void Bfs(int graph[][maxVertices], int *size, int presentVertex,int *visited) { visited[presentVertex] = 1; /* Iterate through all the vertices connected to the presentVertex and perform bfs on those vertices if they are not visited before */ Queue *Q = CreateQueue(maxVertices); Enqueue(Q,presentVertex); while(Q->size) { presentVertex = Front(Q); printf("Now visiting vertex %d\n",presentVertex); Dequeue(Q); int iter; for(iter=0;iter<size[presentVertex];iter++) { if(!visited[graph[presentVertex][iter]]) { visited[graph[presentVertex][iter]] = 1; Enqueue(Q,graph[presentVertex][iter]); } } } return; }
void bfs(int src){ int u, i; reset(); for(i=0;i<MAXN;i++){ dist[i] = INF; } dist[src] = 0; Enqueue(src); while(front != NULL){ u = Front(); Dequeue(); for(i = 1; i <= n;i++){ if(dist[i] > dist[u] + adjMatrix[u][i]){ dist[i] = dist[u] + adjMatrix[u][i]; Enqueue(i); } } } return; }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(800, 600); glutInitWindowPosition(100,100); glutCreateWindow("OGLplus+GLUT+GLEW"); if(glewInit() == GLEW_OK) try { glGetError(); oglplus::Context context; // std::cout << "Limits:" << std::endl; // std::size_t w = 0; for(auto r=oglplus::EnumValueRange<oglplus::LimitQuery>(); !r.Empty(); r.Next()) { std::size_t n = EnumValueName(r.Front()).size(); if(w < n) w = n; } for(auto r=oglplus::EnumValueRange<oglplus::LimitQuery>(); !r.Empty(); r.Next()) { auto ev = r.Front(); std::cout << std::setw(w) << EnumValueName(ev).c_str() << ": "; try { std::cout << context.FloatLimit(ev); } catch(...){ std::cout << "N/A"; } std::cout << std::endl; } return 0; } catch(oglplus::Error& err) { std::cerr << "Error (in " << err.GLSymbol() << ", " << err.ClassName() << ": '" << err.ObjectDescription() << "'): " << err.what() << " [" << err.File() << ":" << err.Line() << "] "; std::cerr << std::endl; err.Cleanup(); } return 1; }
void print_queue(){ if(!isEmpty()){ while(acquire_Mutex(print_Mutex) != xMutex_success);//busy wait while(!isEmpty()){ print(Front()); Dequeue(); } release_Mutex(print_Mutex); } }
void CanvasLayerD3D9::UpdateSurface() { if (!IsDirty() && mTexture) return; Painted(); if (!mTexture) { CreateTexture(); if (!mTexture) { NS_WARNING("CanvasLayerD3D9::Updated called but no texture present and creation failed!"); return; } } // WebGL reads entire surface. LockTextureRectD3D9 textureLock(mTexture); if (!textureLock.HasLock()) { NS_WARNING("Failed to lock CanvasLayer texture."); return; } D3DLOCKED_RECT rect = textureLock.GetLockRect(); IntSize boundsSize(mBounds.width, mBounds.height); RefPtr<DrawTarget> rectDt = Factory::CreateDrawTargetForData(BackendType::CAIRO, (uint8_t*)rect.pBits, boundsSize, rect.Pitch, SurfaceFormat::B8G8R8A8); if (mGLContext) { auto screen = mGLContext->Screen(); MOZ_ASSERT(screen); SharedSurface* surf = screen->Front()->Surf(); if (!surf) return; surf->WaitSync(); if (!ReadbackSharedSurface(surf, rectDt)) { NS_WARNING("Failed to readback into texture."); } } else { RefPtr<SourceSurface> surface = mDrawTarget->Snapshot(); Rect drawRect(0, 0, surface->GetSize().width, surface->GetSize().height); rectDt->DrawSurface(surface, drawRect, drawRect, DrawSurfaceOptions(), DrawOptions(1.0F, CompositionOp::OP_SOURCE)); rectDt->Flush(); } }
int main(void){ Queue Q; int i; Q = CreateQueue(); for(i=0;i<10;i++) EnQueue(i,Q); while(!IsEmpty(Q)){ printf("%d\n",Front(Q)); DeQueue(Q); } for(i=0;i<10;i++) EnQueue(i,Q); while(!IsEmpty(Q)){ printf("%d\n",Front(Q)); DeQueue(Q); } DisposeQueue(Q); return 0; }
int main(void) { // open the default device oalplus::Device device; // create a context using the device and make it current oalplus::ContextMadeCurrent context(device); // std::cout << "Vendor: " << context.Vendor() << std::endl; std::cout << "Version: " << context.Version() << std::endl; std::cout << "Renderer: " << context.Renderer() << std::endl; std::cout << "Device extensions:" << std::endl; for(auto r=device.Extensions(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; std::cout << "Context extensions:" << std::endl; for(auto r=context.Extensions(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; // return 0; }
/* * Draws the "robot" as a triangle facing in the * direction it's initialised as. */ void RobotSim::draw(Mat& src, bool draw_searchRadius) { cv::RotatedRect Rekt = RotatedRect(Position, R_size, angle); Point2f vertices[4]; Rekt.points(vertices); Point2f Front((vertices[2].x+vertices[3].x)/2, (vertices[2].y+vertices[3].y)/2); cv::line(src, vertices[0], Front, Scalar(255,0,0)); cv::line(src, vertices[1], Front, Scalar(255,0,0)); cv::line(src, vertices[0], vertices[1], Scalar(255,0,0)); if(draw_searchRadius){ circle(src, Position, searchRadius, Scalar(0,0,255), 2, 8, 0 ); } }
bool IsContain(Node_t* node) const { MZ_ASSERT_TRUE(!IsNull(node)); auto cursor = Front(); while (!IsNull(cursor)) { if (node == cursor) { return true; } cursor = Forward(cursor); } return false; }
EDA_RECT SELECTION::GetBoundingBox() const { EDA_RECT bbox; bbox = Front()->GetBoundingBox(); auto i = m_items.begin(); ++i; for( ; i != m_items.end(); ++i ) bbox.Merge( (*i)->GetBoundingBox() ); return bbox; }
void QQInfoDlg::InitConnections() { connect(ui.btnBack, SIGNAL(clicked()), ui.edtQQChat, SLOT(Back())); connect(ui.btnFront, SIGNAL(clicked()), ui.edtQQChat, SLOT(Front())); connect(ui.edtQQChat, SIGNAL(FrontShow()), this, SLOT(FrontShow())); connect(ui.edtQQChat, SIGNAL(BackShow()), this, SLOT(BackShow())); connect(ui.edtQQChat, SIGNAL(FrontHide()), this, SLOT(FrontHide())); connect(ui.edtQQChat, SIGNAL(BackHide()), this, SLOT(BackHide())); connect(ui.cmbQQAccount, SIGNAL(currentIndexChanged(int)), this, SLOT(OnCurrentAccountChanged(int))); connect(ui.trQQAccounts, SIGNAL(clicked(const QModelIndex&)), this, SLOT(OnTrQQAccountsClicked(const QModelIndex&))); }
int TItemList::Reduce(int length) { int remain = length; while(remain > 0 && Size() > 0) { TItem* pItem = Front(); remain -= pItem->Reduce(remain); if(pItem->IsEmpty()) itPool.PutFreeItem(PopFront()); } return length - remain; }
int TItemList::Peek(BYTE* pData, int length) { int remain = length; TItem* pItem = Front(); while(remain > 0 && pItem != nullptr) { int peek = pItem->Peek(pData, remain); pData += peek; remain -= peek; pItem = pItem->next; } return length - remain; }
int TItemList::Fetch(BYTE* pData, int length) { int remain = length; while(remain > 0 && Size() > 0) { TItem* pItem = Front(); int fetch = pItem->Fetch(pData, remain); pData += fetch; remain -= fetch; if(pItem->IsEmpty()) itPool.PutFreeItem(PopFront()); } return length - remain; }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(800, 600); glutInitWindowPosition(100,100); glutCreateWindow("OGLplus+GLUT+GLEW"); if(glewInit() == GLEW_OK) try { glGetError(); oglplus::Context context; // std::cout << "Vendor: " << context.Vendor() << std::endl; std::cout << "Version: " << context.Version() << std::endl; std::cout << "Major version: " << context.MajorVersion() << std::endl; std::cout << "Minor version: " << context.MinorVersion() << std::endl; std::cout << "GLSL Version: " << context.ShadingLanguageVersion() << std::endl; std::cout << "Renderer: " << context.Renderer() << std::endl; std::cout << "Extensions:" << std::endl; // for(auto r=context.Extensions(); !r.Empty(); r.Next()) std::cout << '\t' << r.Front() << std::endl; return 0; } catch(oglplus::Error& err) { std::cerr << "Error (in " << err.GLFuncName() << "'): " << err.what() << " [" << err.SourceFile() << ":" << err.SourceLine() << "] " << std::endl; } return 1; }
Ptr<Packet> WimaxMacQueue::Peek (MacHeaderType::HeaderType packetType) const { if (!IsEmpty ()) { QueueElement element = Front (packetType); Ptr<Packet> packet = element.m_packet->Copy (); /*check because may be it is a bandwidth request packet (in which case a Bandwidth Request Header has already been added to the packet) in which case Generic MAC Header will not be added to it. this will only happen in the case of SS as only SS sends the bandwidth request packet. */ if (element.m_hdrType.GetType () == MacHeaderType::HEADER_TYPE_GENERIC) { packet->AddHeader (element.m_hdr); } return packet; } return 0; }
int Bfs(int presentVertex,int *visited, int cluster){ int tempSize=0,success=0; int flag; /*Flag in case the diameter is infinite*/ edge iterEdges; Queue *Q = CreateQueue(vertexNum); /*creates an empty queue in the size of all the vertices*/ visited[presentVertex] = 1; /* Iterate through all the vertices connected to the presentVertex and perform bfs on those vertices if they are not visited before */ Enqueue(Q,presentVertex); while(Q->size){ flag=0; presentVertex = Front(Q); Dequeue(Q); iterEdges=vertices[presentVertex]->edges->head; while(iterEdges!=NULL){ if(iterEdges->inCluster==1 ||iterEdges->inCluster==3){ flag=1; if(visited[iterEdges->id_vertex]==0){ if((vertices[iterEdges->id_vertex])->ClusterBelonging==cluster){ Enqueue(Q,iterEdges->id_vertex); visited[iterEdges->id_vertex]=1; success=1; } } } iterEdges=iterEdges->next; } tempSize=tempSize+success; success=0; } free(Q); if (0==flag){ tempSize=-1; /*-1 means "infinite"*/ } return tempSize; }
main() { int e = 0; unsigned char my_mac[5] = {0xE7,0xD3,0xF0,0x35,0xAA}; QueueRecord *Q; QueueRecord sa; Q = &sa; int *p; DTNMsg* mp; DTNMsg m; int i; MakeEmpty(Q); printf("Enqueue 20 elements...\n"); for (i=0; i<20; i++) { m.prob = rand()%100; Enqueue(m, Q); } PrintQueue(Q); mp = Front(Q); mp->prob = 10; SortQueue(Q); PrintQueue(Q); /* printf("\n Dequeing.......\n"); for (i=0; i<7; i++) printf(" %d ",(FrontAndDequeue(Q)).prob); printf("\n Enqueing.......\n"); for (i=0; i<5; i++) { m.prob = rand()%100; printf(" %d ",m.prob); Enqueue(m, Q); } PrintQueue(Q); SortQueue(Q); for (i=0; i<5; i++) printf(" %d ",(FrontAndDequeue(Q)).prob); */ printf("\n\n"); unsigned char* mac; mac = my_mac; for(i=0;i<5;i++) printf("%x",mac[i]); unsigned int x; x= 0x0000000F; x=(x<<4)|0xF; unsigned int xx = 0x00000000; for(i = 0 ;i<=5;i++){ x = ((0x00000000 | 0x89B0)<<16) | xx++; printf("\n\nx = %x\n",x);} }
int main() { // open the default display eglplus::Display display; // initialize the library eglplus::LibEGL egl(display); // get the list of all available configurations eglplus::Configs configs(display); // int w = 20; for(auto cr = configs.All(); !cr.Empty(); cr.Next()) { auto cfg = cr.Front(); std::cout << "Config ID = " << cfg.ConfigId() << std::endl; std::cout << "\tRed size: " << std::setw(w) << cfg.RedSize() << std::endl; std::cout << "\tGreen size: " << std::setw(w) << cfg.GreenSize() << std::endl; std::cout << "\tBlue size: " << std::setw(w) << cfg.BlueSize() << std::endl; std::cout << "\tAlpha size: " << std::setw(w) << cfg.AlphaSize() << std::endl; std::cout << "\tDepth size: " << std::setw(w) << cfg.DepthSize() << std::endl; std::cout << "\tStencil size: " << std::setw(w) << cfg.StencilSize() << std::endl; std::cout << "\tMax Pbuffer width: " << std::setw(w) << cfg.MaxPbufferWidth() << std::endl; std::cout << "\tMax Pbuffer height:" << std::setw(w) << cfg.MaxPbufferHeight() << std::endl; std::cout << "\tMax Pbuffer pixels:" << std::setw(w) << cfg.MaxPbufferPixels() << std::endl; std::cout << "\tConfig caveat: " << std::setw(w) << eglplus::EnumValueName(cfg.ConfigCaveat()).c_str() << std::endl; std::cout << "\tColor buffer type: " << std::setw(w) << eglplus::EnumValueName(cfg.ColorBufferType()).c_str() << std::endl; std::cout << "\tTransparent type: " << std::setw(w) << eglplus::EnumValueName(cfg.TransparentType()).c_str() << std::endl; std::cout << "\tRenderable types: " << std::setw(w); auto rtr = eglplus::EnumValueRange<eglplus::RenderableTypeBit>(); while(!rtr.Empty()) { if(cfg.HasRenderableType(rtr.Front())) { std::cout << eglplus::EnumValueName(rtr.Front()).c_str(); std::cout << '|'; } rtr.Next(); } std::cout << std::endl; std::cout << "\tSurface types: " << std::setw(w); auto str = eglplus::EnumValueRange<eglplus::SurfaceTypeBit>(); while(!str.Empty()) { if(cfg.HasSurfaceType(str.Front())) { std::cout << eglplus::EnumValueName(str.Front()).c_str(); std::cout << '|'; } str.Next(); } std::cout << std::endl; std::cout << "\tConformant to: " << std::setw(w); auto ctr = eglplus::EnumValueRange<eglplus::RenderableTypeBit>(); while(!ctr.Empty()) { if(cfg.IsConformantTo(ctr.Front())) { std::cout << eglplus::EnumValueName(ctr.Front()).c_str(); std::cout << '|'; } ctr.Next(); } std::cout << std::endl; std::cout << "-----------------------------------------------" << std::endl; } // return 0; }
byte BidirBuffer::PopFront() { byte result = *Front(); SetDataOffset(GetDataOffset() + 1, m_dataSize - 1); return result; }
void BidirBuffer::PushFront(const void* pSrc, int size ) { if (size == 0) return; // ignore SetDataOffset(GetDataOffset() - size, m_dataSize + size); memcpy(Front(), pSrc, size); }
void MyProduceConsume::Consume() { if (false == IsEmpty()) { printf("pop %d\n", *Front()); Pop(); } }