int main()
{
	struct Node* node5 = (struct Node*)malloc(sizeof(struct Node));
	node5->Data = 5;
	node5->Next = NULL;
	struct Node* node4 = (struct Node*)malloc(sizeof(struct Node));
	node4->Data = 4;
	node4->Next = node5;
	struct Node* node3 = (struct Node*)malloc(sizeof(struct Node));
	node3->Data = 3;
	node3->Next = node4;
	struct Node* node2 = (struct Node*)malloc(sizeof(struct Node));
	node2->Data = 2;
	node2->Next = node3;
	struct Node* node1 = (struct Node*)malloc(sizeof(struct Node));
	node1->Data = 1;
	node1->Next = node2;

	struct Node* head = node1;
	node5->Next = node2;

	struct Node* Node = EntryNode(head);
	printf("\nEntry point of loop is at Node %d",Node->Data);
	return 0;

}
int main(void) {
	struct Node* node05 = (struct Node *)malloc(sizeof(struct Node));
		node05->Value = 7;
		node05->Next = NULL;
		struct Node* node04 = (struct Node *)malloc(sizeof(struct Node));
		node04->Value = 4;
		node04->Next = node05;
		struct Node* node03 = (struct Node *)malloc(sizeof(struct Node));
		node03->Value = 3;
		node03->Next = node04;
		struct Node* node02 = (struct Node *)malloc(sizeof(struct Node));
		node02->Value = 2;
		node02->Next = node03;
		struct Node* node01 = (struct Node *)malloc(sizeof(struct Node));
		node01->Value = 1;
		node01->Next = node02;
		struct Node* head1 = node01;
		node05->Next = node02;

		//node02 = head1->Next->Next->Next->Next;
		struct Node* node = EntryNode(head1);
		printf("\nEntry point of loop is at Node %d",node->Value);
		return 0;

}
Esempio n. 3
0
/*--------------------------------------------------------------------
Purpose:
  Get the elements and nodes on the velocity mesh that are touched by the particle.
  The elements may be partly inside, but only nodes inside are registered

Input:
  d: data structure
  particle: the particle
  element: current element checked
  NodeVisited: node visited is marked in the list of all nodes
  ElemVisited: element visited is marked in list of all elements

Output:
  ElemTouched: list of elements touched by the particles,
  ElemTouchedNodeIn: list of elements partly/fully inside the particles,
  nodesIS: list of nodes touched by the particles

By: Veeramani
Update: 29/Sep/06 Antoine
--------------------------------------------------------------------*/
static void
ParElemNodeTouchWrapped(
const mesh_t*     mesh,
const particle_t* particle,
const int      element,
      int**    ElemTouchedPtr,
      int**    ElemTouchedNodeInPtr,
      int**    NodeInPtr,
      bool*       NodeVisited,
      bool*       ElemVisited )
{
  int node, theNode, iElem, nextEl,
        NodeInPar,
        count; // Temporary variable for keeping count

  ElemVisited[ element ] = true;
  
  // get the number of nodes of element in particle
  NodeInPar = ElemNodeNbInPar( mesh, particle, element );

  if ( NodeInPar )
  {
    // increment the number of elements touched
    count = ++(*ElemTouchedPtr)[ 0 ];
    
    // Reallocate only when count exceeds a multiple of memory block
    if ( ( count % MBLOCK ) == 1 )
    {
      *ElemTouchedPtr = (int*) realloc( (*ElemTouchedPtr), ( count + MBLOCK ) * sizeof(int) );
      assert_error( *ElemTouchedPtr != NULL, "Memory allocation error");
    }
    
    (*ElemTouchedPtr)[ count ] = element;

    count = ++(*ElemTouchedNodeInPtr)[ 0 ];
    
    // Reallocate only when count exceeds a multiple of memory block
    if ( ( count % MBLOCK ) == 1 )
    {
      *ElemTouchedNodeInPtr = (int*) realloc( (*ElemTouchedNodeInPtr), ( count + MBLOCK ) * sizeof(int) );
      assert_error( *ElemTouchedNodeInPtr != NULL, "Memory allocation error");
    }
    (*ElemTouchedNodeInPtr)[ count ] = NodeInPar;

    // check neighbouring elements recursively
    for ( node = 1 ; node <= NODES_PER_EL ; node++ )
    {
      theNode = mesh->ConTab[ element ][ node ];
      
      if ( NodeVisited[ theNode ] == false )
      {
        NodeVisited[ theNode ] = true;

        // Check whether node is inside the particle
        if ( IsNodeInPar( mesh, particle, theNode ) )
        {
          count = ++(*NodeInPtr)[ 0 ];
          
          // Reallocate only when count exceeds a multiple of memory block
          if ( ( count % MBLOCK ) == 1 )
          {
            *NodeInPtr = ( int * ) realloc( (*NodeInPtr), ( count + MBLOCK ) * sizeof(int) );
            assert_error( *NodeInPtr != NULL, "Memory allocation error");
          }
          
          (*NodeInPtr)[ count ] = theNode;
        }

        // check in inverse ConTab
        for ( iElem = 1 ; iElem <= NbOfEntriesInRow(mesh->InvConTab, theNode-1);  iElem++ )
        {
          nextEl = EntryNode(mesh->InvConTab, theNode-1, iElem-1);
          
          if ( ElemVisited[ nextEl ] == false )
            ParElemNodeTouchWrapped(
              mesh, particle, nextEl,
              ElemTouchedPtr, ElemTouchedNodeInPtr, NodeInPtr, NodeVisited, ElemVisited );
        }
      }
    }
  }
}