Exemplo n.º 1
0
/* calculates a set of node tangents */
void calc_tangents(void)
{
   int i;

   nodes[0] = dummy_node(nodes[1], nodes[2]);
   nodes[node_count] = dummy_node(nodes[node_count-1], nodes[node_count-2]);
   node_count++;

   for (i=1; i<node_count-1; i++)
      nodes[i].tangent = fixatan2(itofix(nodes[i+1].y - nodes[i-1].y),
				  itofix(nodes[i+1].x - nodes[i-1].x));
}
Exemplo n.º 2
0
 void initialize(void)
 {
     node * n = pool.template construct<true, false>(pool.null_handle());
     tagged_node_handle dummy_node(pool.get_handle(n), 0);
     head_.store(dummy_node, memory_order_relaxed);
     tail_.store(dummy_node, memory_order_release);
 }
Exemplo n.º 3
0
    ListNode *mergeKLists(vector<ListNode *> &lists) {
        // Note: The Solution object is instantiated only once and is reused by each test case.
        ListNode dummy_node(0);
        ListNode* cur = &dummy_node;

        vector<ListNode*>::iterator it_lhs = lists.begin();
        vector<ListNode*>::iterator it_rhs = lists.end();
        it_rhs = std::remove_if(it_lhs, it_rhs, isNull);
        lists.resize(std::distance(it_lhs, it_rhs));

        std::make_heap(lists.begin(), lists.end(), cmpNodes);

        while (lists.begin() != lists.end()) {
            cur->next = lists.front();
            cur = cur->next;

            std::pop_heap(lists.begin(), lists.end(), cmpNodes);
            lists.pop_back();

            if (cur->next) {
                lists.push_back(cur->next);
                std::push_heap(lists.begin(), lists.end(), cmpNodes);
            }
        }
        assert(cur->next == NULL);

        return dummy_node.next;
    }
Exemplo n.º 4
0
/* calculates a set of node tangents */
void calc_tangents(void)
{

     //pas touche prepa tangentes OK pour sens en avant
   int i;

   nodes[0] = dummy_node(nodes[node_count+1], nodes[node_count]);//node et previous
   nodes[node_count+1] = dummy_node(nodes[node_count], nodes[0]);

   node_count++;

  for (i=1; i<node_count-1; i++)
      nodes[i].tangent = fixatan2(itofix(nodes[i+1].y - nodes[i-1].y),
				  itofix(nodes[i+1].x - nodes[i-1].x));



}
//****************************************************************************
//My second solution which passes the time requirement in leetcode
ListNode* partition(ListNode* head, int x) {
    
  if(head==NULL ||head->next==NULL){return head;}
    
  int y=x-1;
  ListNode dummy_node(y);
  dummy_node.next=head;
  head=&dummy_node;         //create a dummy node for convinient
    
  ListNode*tail_ptr=head,*prev_ptr=head,*cur_ptr=head->next,*fixedEnd_ptr;
    
  for(;tail_ptr->next!=NULL;tail_ptr=tail_ptr->next){}
    
  fixedEnd_ptr=tail_ptr;
    
  while(cur_ptr!=fixedEnd_ptr)
    {
      if(cur_ptr->val>=x)
        {
	  tail_ptr->next=cur_ptr;
	  cur_ptr=cur_ptr->next;
	  prev_ptr->next=cur_ptr;
	  tail_ptr=tail_ptr->next;
	  tail_ptr->next=NULL;
	  continue;
        }
      cur_ptr=cur_ptr->next;
      prev_ptr=prev_ptr->next;
    }
  if(tail_ptr!=fixedEnd_ptr)   //If tail_ptr==fixed_ptr means that no node is greater or equal to the x number and even if the last node is greater or equal to the number we dont have to move it.
        
    {//cur is now pointing to the fixed node
      if(cur_ptr->val>=x)
        {
	  tail_ptr->next=cur_ptr;   //or fixed_pointer
	  prev_ptr->next=cur_ptr->next;
	  cur_ptr->next=NULL;
        }
        
    }
  return head->next;
}
Exemplo n.º 6
0
/* draws the spline paths */
int draw_splines(int move_selected)
{
   int io;
     nodes[0] = dummy_node(nodes[node_count+1], nodes[node_count]);//node et previous
   for (io=1; io<node_count; io++)
   {
      nodes[io].x=(dock_move_xy[move_selected][io][0]+xmover_window+20);
      nodes[io].y=(dock_move_xy[move_selected][io][1]+ymover_window+20);
   }

   for (io=1; io<node_count-1; io++)
   {
    draw_spline(nodes[io], nodes[io+1]);
   }


  // goback to begin
  draw_spline(nodes[node_count], nodes[1]);

return(0);
}