void main(void){
	int i;
	int j;
	struct Tree *top;
	struct Tree *child;
	for(i=0;i<1000000;i++){
		top = Create_Node(BUFF_LEN);
		child = Create_Node(BUFF_LEN);
		Add_Next(top,child);
		for(j=0;j<(*top).NextCount;j++){
			free((*top).Next[j]);
		}
		free(top);
		printf("%d\n",i);
	}
}
Пример #2
0
void Create_List(pComplexNode *phead)
{
	pComplexNode pnode1 = Create_Node(1);
	pComplexNode pnode2 = Create_Node(2);
	pComplexNode pnode3 = Create_Node(3);
	pComplexNode pnode4 = Create_Node(4);
	pnode1->pnext = pnode2;
	pnode2->pnext = pnode3;
	pnode3->pnext = pnode4;

	pnode1->prand = pnode4;
	pnode2->prand = NULL;
	pnode3->prand = pnode2;
	pnode4->prand = pnode1;
	
	(*phead) = pnode1;
}
void main(void){
	int i;
	struct Tree *top;
	for(i=0;i<1000000;i++){
		top = Create_Node(BUFF_LEN);
		free(top);
		printf("%d\n",i);
	}
}
Пример #4
0
// Loads the input file into a structure
Node * Load_File(char * input_file)
{
  FILE * iptr = fopen(input_file, "r");

  // Check for file opening errors
  if(iptr == NULL)
  {
    printf("Error opening input file\n");
    return NULL;
  }

  int numbers = 0;
  long temp; // Temp variable used to count the number of items in the input file

  while(fscanf(iptr, "%li", &temp) == 1)
  {
    numbers++;
  }

  // Set the file to the beginning
  fseek(iptr, 0, SEEK_SET);

  Node * dummy = malloc(sizeof(Node));

  // Check for memory allocation errors
  if(dummy == NULL)
  {
    printf("Memory allocation failed\n");
    return NULL;
  }

  // Create a dummy node that contains the number of items in the linked list that follows (Very useful, thanks for the idea Professor Koh)
  dummy -> value = numbers;
  dummy -> next = NULL;

  Node * root = NULL, * prev = NULL;

  // Create a linked list in reverse order (More efficient)
  while(numbers--)
  {
    // Make sure the item in scanned
    if(!fscanf(iptr, "%li", &temp))
    {
      printf("Error scanning in the input values\n");
      return NULL;
    }

    root = Create_Node(temp);

    if(root == NULL)
    {
      root -> next = NULL;
    }
    else
    {
      root -> next = prev;
    }

    prev = root;
  }

  // Place the dummy node at the front of the linked lists
  dummy -> next = root;

  // Close the file
  fclose(iptr);

  // Return the linked list with the dummy node at the front
  return dummy;
}
Пример #5
0
//INSERISCO UNA PARTICELLA NELL'ALBERO, TRASFORMANDO UN NODO FOGLIA IN UN RAMO
void Insert_Body(struct body *insbody, struct node *nodep){
    
    enum quadrant existingquad, newquad;
    double xmid, ymid;
    
    xmid = nodep->xmin + 0.5*(nodep->xmax - nodep->xmin);
    ymid = nodep->ymin + 0.5*(nodep->ymax - nodep->ymin);
    
    
    //se il nodo è una foglia la trasformo in ramo ed inserisco la particella in un nuovo sotto quadrante
    if(nodep->bodyp != NULL){
        existingquad=Get_Quadrant(nodep->bodyp->x, nodep->bodyp->y, nodep->xmin, nodep->xmax, nodep->ymin, nodep->ymax);
        
        switch (existingquad) {
            case NO:
                nodep->NO = Create_Node(nodep->bodyp, xmid, nodep->xmax, ymid, nodep->ymax);
                break;
            case NW:
                nodep->NW = Create_Node(nodep->bodyp, nodep->xmin, xmid, ymid, nodep->ymax);
                break;
            case SW:
                nodep->SW = Create_Node(nodep->bodyp, nodep->xmin, xmid, nodep->ymin, ymid);
                break;
            case SO:
                nodep->SO = Create_Node(nodep->bodyp, xmid, nodep->xmax, nodep->ymin, ymid);
                break;
        }
        
        nodep->bodyp = NULL;
    }

    
    newquad = Get_Quadrant(insbody->x, insbody->y, nodep->xmin, nodep->xmax, nodep->ymin, nodep->ymax);
    Update_Center_Mass(nodep,insbody);
    
    //inserisco un nuovo punto in un nuovo quadrante se questo è vuoto altrimenti chiamo ricorsivamente Insert_Body
    switch (newquad){
        case NO:
            if(nodep->NO == NULL)
            {
                nodep->NO = Create_Node(insbody, xmid, nodep->xmax, ymid, nodep->ymax);
            } else {
                Insert_Body(insbody,nodep->NO);
            }
            break;
        case NW:
            if(nodep->NW == NULL)
            {
                nodep->NW = Create_Node(insbody, nodep->xmin, xmid, ymid, nodep->ymax);
            } else {
                Insert_Body(insbody,nodep->NW);
            }
            break;
        case SW:
            if(nodep->SW == NULL)
            {
                nodep->SW = Create_Node(insbody, nodep->xmin, xmid, nodep->ymin, ymid);
            } else {
                Insert_Body(insbody,nodep->SW);
            }
            break;
        case SO:
            if(nodep->SO == NULL)
            {			
                nodep->SO = Create_Node(insbody, xmid, nodep->xmax, nodep->ymin, ymid);
            } else {			
                Insert_Body(insbody,nodep->SO);
            }
            break;
    }
    
    
}