/* * Quatre cas possible * Deux verticales, Deux horizontales. * * A voir si on modifie ici l'espace et les voisins de trg ou pas. */ int manageSpaceInsert(node* src, node* trg) { src->area = getNodesSubSpace(trg); if( src->area->south_west->x == trg->area->south_west->x ){ /* séparation horizontale (2 cas) ou verticale avec src a gauche */ if( src->area->south_west->y == trg->area->south_west->y ){ /* séparation horizontale src sous trg ou verticale avec src a gauche */ if( src->area->north_east->y == trg->area->north_east->y ){ /* Src a GAUCHE de Trg */ /* Voisin de src */ src->neighbors[EAST]->n = newListNode(trg, NULL); src->neighbors[WEST]->n = cloneListNode(trg->neighbors[WEST]); /* A voir en fonction des espaces */ src->neighbors[NORTH]->n = cloneListNode(trg->neighbors[NORTH]); src->neighbors[SOUTH]->n = cloneListNode(trg->neighbors[SOUTH]); }else{ /* Src en BAS de Trg */ /* Voisin de src */ src->neighbors[NORTH]->n = newListNode(trg, NULL); src->neighbors[SOUTH]->n = cloneListNode(trg->neighbors[SOUTH]); /* A voir en fonction des espaces */ src->neighbors[EAST]->n = cloneListNode(trg->neighbors[EAST]); src->neighbors[WEST]->n = cloneListNode(trg->neighbors[WEST]); } }else{ /* Src a en HAUT de Trg */ /* Voisin de src */ src->neighbors[NORTH]->n = cloneListNode(trg->neighbors[NORTH]); src->neighbors[SOUTH]->n = newListNode(trg, NULL); /* A voir en fonction des espaces */ src->neighbors[EAST]->n = cloneListNode(trg->neighbors[EAST]); src->neighbors[WEST]->n = cloneListNode(trg->neighbors[WEST]); } } else{ /* Src à DROITE de Trg */ /* Voisin de src */ src->neighbors[EAST]->n = cloneListNode(trg->neighbors[EAST]) src->neighbors[WEST]->n = newListNode(trg, NULL); /* A voir en fonction des espaces */ src->neighbors[NORTH]->n = cloneListNode(trg->neighbors[NORTH]); src->neighbors[SOUTH]->n = cloneListNode(trg->neighbors[SOUTH]); } return 1; }
void listAppend(List *list, void *value, Region *r) { ListNode *ln = newListNode(value, r); if(list->head != NULL) { list->tail = list->tail->next = ln; } else { list->head = list->tail = ln; } }
void registerConditionDisplay(struct WeatherData *wd, void *currentConditionDisplay) { CurrentConditionDisplay *ccd = (CurrentConditionDisplay *)currentConditionDisplay; doublyLinkedList *list = (doublyLinkedList *)wd->conditionDisplayList; listNode *node = newListNode((void *)ccd); list->push(list, node); }
List listInit(void) { List root = newListNode(); root->isRoot = 1; root->n = NULL; root->p = NULL; return root; }
void listAppendToNode(List *list, ListNode *node, void *value, Region *r) { ListNode *ln = newListNode(value, r); if(node->next != NULL) { ln->next = node->next; node->next = ln; } else { node->next = list->tail = ln; } }
Node * buiList(ListNode * args, Env * env) { if (args->car == NULL) return (Node *) &nil; ListNode * t = newListNode(eval(args->car, env), (Node *)&nil), * s = t; for(args = args->cdr; args && args != &nil; args = args->cdr) { t = append(t, eval(args->car, env))->cdr; } t->cdr = &nil; return (Node *) s; }
/* * Creates a list that starts with a NULL node. * * Returns: * The newly allocated linked list */ LList *newList( ComparisonFunction comparisonFunction ) { LList *list = malloc( sizeof(LList) ); list->size = 0; list->head = newListNode(NULL, NULL); if( comparisonFunction != NULL ) { list->comparisonFunction = comparisonFunction; } return list; }
game_obj* newDoor(game_obj* list, float x, float y, float z) { game_obj* door = newListNode(list); door->type = DOOR; door->data = (float *)malloc(sizeof(float)); door->coords.x = x; door->coords.y = y; door->coords.z = z; doorInit(door); return door; }
void addInList(list* nodelist,node* thisnode) { listnode* newnode = newListNode(thisnode) ; if(nodelist->firstnode == NULL) { nodelist->firstnode = newnode ; } else { listnode* temp = nodelist->firstnode ; while(temp->next != NULL) { temp = temp->next ; } temp->next = newnode ; } nodelist->sz += 1 ; }
List listAddAfter(List root, List place, void* val) { List ptr; ptr = newListNode(); ptr->isRoot = 0; ptr->v = val; ptr->n = place->n; if (!place->isRoot) ptr->p = place; else ptr->p = NULL; if (place->n) place->n->p = ptr; place->n = ptr; if (ptr->n == NULL) root->p = ptr; return ptr; }
/* * Inserts the element into the list. * * Arguments: * list -- The to add the element into * data -- The data to be added into the list */ void listInsert( LList *list, void *data ) { // You cannot insert NULL into the list if( data == NULL ) { return; } ListNode *current = list->head; ComparisonFunction compare = list->comparisonFunction; // Determine where the data will be inserted while( current->next != NULL && compare(current->data, data) < 0 ) { current = current->next; } // Insert the element ListNode *tempNode = newListNode( current->data, current->next ); current->data = data; current->next = tempNode; list->size += 1; }
// Function to add an edge between two nodes void addEdge(struct Graph* G, int node1, int node2, int weight) { struct listNode* newNode = newListNode(node2); newNode->weight = weight; newNode->next = (G->arr)[node1].next; (G->arr)[node1].next = newNode; }