void R_s_k_2::draw_bins_plan1(const Edge& edge) { FT M = m_dt.get_mass(edge); Vector va = m_dt.source_vertex(edge)->point() - CGAL::ORIGIN; Vector vb = m_dt.target_vertex(edge)->point() - CGAL::ORIGIN; viewer->glColor3f(1.0f, 0.0f, 0.0f); SQueue queue; FT start = 0.0; m_dt.sort_samples_from_edge(edge, queue); while (!queue.empty()) { PSample psample = queue.top(); queue.pop(); const FT m = psample.sample()->mass(); const Point& ps = psample.sample()->point(); FT bin = m/M; FT alpha = start + 0.5*bin; Point q = CGAL::ORIGIN + (1.0-alpha)*va + alpha*vb; start += bin; draw_segment(ps, q); } }
int main() { int start, end, elapsed; double seconds; start = clock(); //get starting ticks //start of code to be timed cout << "Running timing test for std list-based queue implementation" << endl; SQueue* queue = new SQueue(); for(long i=1;i<=100000;++i){ for(long j=1;j<=100;++j){ queue->enqueue(j); } } cout << "The queue is currently " << queue->size() << " elements is size" << endl; for(long x=1;x<=100000;++x){ for(long y=1;y<=100;++y){ queue->dequeue(); } } cout << "The queue is now " << queue->size() << " elements in size" << endl; delete queue; //end of code to be timed end = clock(); //get ending ticks elapsed = end-start; //calculate total elapsed ticks seconds = (double) elapsed/CLOCKS_PER_SEC; //convert to seconds cout << "Elapsed time for this procedure is : " << seconds << " seconds " << endl; return 0; }
int main() { int length, width, tmp; cin >> length >> width; SQueue window; int result_size = length - width + 1; int maxs[result_size], mins[result_size]; for(int i = 0; i < width; i++) { cin >> tmp; window.push(tmp); } maxs[0] = window.max(); mins[0] = window.min(); for(int j = 1; j < result_size; j++) { window.pop(); cin >> tmp; window.push(tmp); maxs[j] = window.max(); mins[j] = window.min(); } //cout << endl; for(int a = 0; a < result_size; a++) { cout << mins[a] << " "; } cout << endl; for(int b = 0; b < result_size; b++) { cout << maxs[b] << " "; } cout << endl; return 0; }
int main () { typedef std::queue<int, std::list<int, std::allocator<int> > > IQueue; // Make a queue using a deque container. IQueue q; // Push a couple of values on and retrieve them. q.push (1); q.push (2); std::cout << q.front () << std::endl; std::cout << q.back () << std::endl; typedef std::queue<std::string, std::deque<std::string, std::allocator<std::string> > > SQueue; // Make a queue of strings using a deque container. SQueue qs; // Push on a few strings then pop them back off. for (std::string::size_type i = 0U; i != 10U; i++) { qs.push (std::string (i + 1, 'a')); std::cout << qs.front () << std::endl; } for (std::string::size_type j = 0U; j != 10U; j++) { std::cout << qs.front () << std::endl; qs.pop (); } // Return 0 if both containers are empty, a non-zero value otherwise. return !(2 == q.size () && qs.empty ()); }
int main() { clock_t start=clock(); //initialization of clock int i,j; SQueue <int> Q; int row,column; //rows and columns in the maze cout<<"Enter the number of rows"<<endl; cin>>row; cout<<"Enter the number of Columns"<<endl; cin>>column; int sizeofmaze; sizeofmaze=row*column; //calculating the number of cells struct map cell[sizeofmaze]; //an array of structure map cout<<"Enter the map of the maze"<<endl; for(int i=0;i<sizeofmaze;i++) //input the map of the maze { cin>>cell[i].left; cin>>cell[i].top; cin>>cell[i].right; cin>>cell[i].bottom; } int pos=0; //initialize cellpos to 0i.e starting int flag=0,flag2=0,exitgates=0; cell[pos].left='0'; int temp= pos+1; Q.Enqueue(temp); if(cell[pos].right=='1') { cell[pos].right='0'; flag=1; pos=pos+1; } else { cell[pos].bottom='0'; pos=pos+column; flag=2; } do { do { if(flag==1) cell[pos].left='0'; else if(flag==2) cell[pos].top='0'; else if(flag==3) cell[pos].right='0'; else if(flag==4) cell[pos].bottom='0'; else // just to fill the else codition basically it does nothing { flag++; flag--; } Q.Enqueue(pos+1); if(cell[pos].left=='1') //condition for cell to have its left end open { cell[pos].left='0'; flag=3; i=(pos)/row; j=(pos)%column; j--; if(j<0) {flag2=1;} else {pos=pos-1;} } else if(cell[pos].top=='1') //condition for the cell to have its top end open { cell[pos].top='0'; flag=4; i=(pos)/row; j=(pos)%column; i--; if(i<0) {flag2=1;} else {pos=pos-column;} } else if(cell[pos].right=='1') //condition for the cell to have its right end open { cell[pos].right='0'; flag=1; i=(pos)/row; j=(pos)%column; j++; if(j>=column) {flag2=1;} else {pos=pos+1;} } else if(cell[pos].bottom=='1') //condition for the cell to have its bottom end open { cell[pos].bottom='0'; flag=2; i=(pos)/row; j=(pos)%column; i++; if(i>=row) {flag2=1;} else {pos=pos+column;} } else //code changed here for blocked path; rest is same { flag2=2; cout<<"Dead end"<<endl; Q.display(); //displaying the dead end} } }while(flag2==0); //this is the condition when the mouse exits the maze if(flag2==1) { exitgates++; cout<<exitgates<<" exit path is"<<endl; Q.display(); } flag2=0; int check; do //loop checks the number of openings available in the cell and returns to the cell where more than one path exists { pos=Q.Deque(); pos=pos-1; check=nop(cell,pos); }while(check==0&&Q.isEmpty()==0); //for inner loop to check if any way in a particular cell is left unexplored flag=0; }while(Q.isEmpty()==0); //for outer loop when the queue goes empty cout<<"Total number of exit gates are "<<exitgates<<endl; //displays the number of exit gates printf("Time : %f\n",((double)clock()-start)/CLOCKS_PER_SEC); system("pause"); return 0; }