void deleteX(int x) { node* tempNode = ALLOC_NODE(); if(ourList->head->data == x) deleteFirst(); if(ourList->tail->data == x) deleteLast(); tempNode = ourList->head; int i; for(i=0; i < ourList->length; i++) { tempNode = tempNode->next; if(tempNode->data == x) { tempNode->prev->next = tempNode->next; tempNode->next->prev = tempNode->prev; node* auxNode = ALLOC_NODE(); auxNode = tempNode; tempNode = tempNode->next; free(auxNode); tempNode = tempNode->prev; } } }
void testTwoElementListNoCycle(void){ Node* a = ALLOC_NODE(); Node* b = ALLOC_NODE(); a->next = b; ASSERT_FALSE(floyd_has_cycle(a),"Two element list should not have cycles"); ASSERT_FALSE(brent_has_cycle(a),"Two element list should not have cycles"); free(a); free(b); }
static fringe_node_c * alloc_vertex(ModeInfo * mi, angle_c dir, fringe_node_c * from, tiling_c * tp) { fringe_node_c *v; if ((v = ALLOC_NODE(fringe_node_c)) == NULL) { tp->done = True; if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "No memory in alloc_vertex()\n"); } tp->busyLoop = CELEBRATE; return v; } *v = *from; add_unit_vec(dir, v->fived); fived_to_loc(v->fived, tp, &(v->loc)); if (v->loc.x < 0 || v->loc.y < 0 || v->loc.x >= tp->width || v->loc.y >= tp->height) { v->off_screen = True; if (v->loc.x < -tp->width || v->loc.y < -tp->height || v->loc.x >= 2 * tp->width || v->loc.y >= 2 * tp->height) tp->done = True; } else { v->off_screen = False; tp->fringe.n_nodes++; } v->n_tiles = 0; v->rule_mask = (1 << N_VERTEX_RULES) - 1; v->list_ptr = 0; return v; }
void doom() { node* tempNode = ALLOC_NODE(); node* auxNode = ALLOC_NODE(); tempNode = ourList->head; auxNode = tempNode; while(tempNode != NULL) { tempNode = tempNode->next; free(auxNode); auxNode = tempNode; } ourList->head = NULL; ourList->tail = NULL; ourList->length = 0; }
node* createNode(int data) { node* tempNode = ALLOC_NODE(); tempNode->next = NULL; tempNode->prev = NULL; tempNode->data = data; return tempNode; }
/*- * Update the status of this vertex on the forced vertex queue. If * the vertex has become untileable set tp->done. This is supposed * to detect dislocations -- never call this routine with a completely * tiled vertex. * * Check for untileable vertices in check_vertex and stop tiling as * soon as one finds one. I don't know if it is possible to run out * of forced vertices while untileable vertices exist (or will * cavities inevitably appear). If this can happen, add_random_tile * might get called with an untileable vertex, causing ( n <= 1). * (This is what the tp->done checks for). * * A delayLoop celebrates the dislocation. */ static void check_vertex(ModeInfo * mi, fringe_node_c * vertex, tiling_c * tp) { rule_match_c hits[MAX_TILES_PER_VERTEX * N_VERTEX_RULES]; int n_hits = match_rules(vertex, hits, False); unsigned forced_sides = 0; if (vertex->rule_mask == 0) { tp->done = True; if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Dislocation occurred!\n"); } tp->busyLoop = CELEBRATE; /* Should be able to recover */ } if (1 == find_completions(vertex, hits, n_hits, S_LEFT, 0 /*, False */ )) forced_sides |= S_LEFT; if (1 == find_completions(vertex, hits, n_hits, S_RIGHT, 0 /*, False */ )) forced_sides |= S_RIGHT; if (forced_sides == 0) { if (vertex->list_ptr != 0) { forced_node_c *node = *vertex->list_ptr; *vertex->list_ptr = node->next; if (node->next != 0) node->next->vertex->list_ptr = vertex->list_ptr; free(node); tp->forced.n_nodes--; if (!vertex->off_screen) tp->forced.n_visible--; vertex->list_ptr = 0; } } else { forced_node_c *node; if (vertex->list_ptr == 0) { if ((node = ALLOC_NODE(forced_node_c)) == NULL) return; node->vertex = vertex; node->next = tp->forced.first; if (tp->forced.first != 0) tp->forced.first->vertex->list_ptr = &(node->next); tp->forced.first = node; vertex->list_ptr = &(tp->forced.first); tp->forced.n_nodes++; if (!vertex->off_screen) tp->forced.n_visible++; } else node = *vertex->list_ptr; node->forced_sides = forced_sides; } }
void printList() { node* tempNode = ALLOC_NODE(); tempNode = ourList->head; FILE* f = fopen("output.dat", "a"); while(tempNode != NULL) { fprintf(f, "%d ", tempNode->data); tempNode = tempNode->next; } fprintf(f, "\n"); fclose(f); }
void deleteLast() { if(ourList->head == ourList->tail) { free(ourList->tail); ourList->head = NULL; ourList->tail = NULL; ourList->length=0; } else { node* tempNode = ALLOC_NODE(); tempNode = ourList->tail; ourList->tail = ourList->tail->prev; free(tempNode); ourList->length--; } }
void deleteFirst() { if(ourList->head == ourList->tail) { free(ourList->head); ourList->head = NULL; ourList->tail = NULL; ourList->length=0; } else { node* tempNode = ALLOC_NODE(); tempNode = ourList->head; ourList->head = ourList->head->next; free(tempNode); ourList->length--; } }
void printLast(int x) { FILE* f = fopen("output.dat", "a"); node* tempNode = ALLOC_NODE(); tempNode = ourList->tail; int i; for(i = 1; i < x; i++) if(tempNode->prev != NULL) tempNode = tempNode->prev; while(tempNode != NULL) { fprintf(f, "%d ", tempNode->data); tempNode = tempNode->next; } fprintf(f, "\n"); fclose(f); }
/* Called to init the mode. */ void init_penrose(ModeInfo * mi) { tiling_c *tp; fringe_node_c *fp; int i, size; if (tilings == NULL) { if ((tilings = (tiling_c *) calloc(MI_NUM_SCREENS(mi), sizeof (tiling_c))) == NULL) return; } tp = &tilings[MI_SCREEN(mi)]; if (MI_IS_FULLRANDOM(mi)) tp->ammann = (Bool) (LRAND() & 1); else tp->ammann = ammann; tp->done = False; tp->busyLoop = 0; tp->failures = 0; tp->width = MI_WIDTH(mi); tp->height = MI_HEIGHT(mi); if (MI_NPIXELS(mi) > 2) { tp->thick_color = NRAND(MI_NPIXELS(mi)); /* Insure good contrast */ tp->thin_color = (NRAND(2 * MI_NPIXELS(mi) / 3) + tp->thick_color + MI_NPIXELS(mi) / 6) % MI_NPIXELS(mi); } else { if (LRAND() & 1) { tp->thick_color = MI_WHITE_PIXEL(mi); tp->thin_color = MI_BLACK_PIXEL(mi); } else { tp->thick_color = MI_BLACK_PIXEL(mi); tp->thin_color = MI_WHITE_PIXEL(mi); } } size = MI_SIZE(mi); if (size < -MINSIZE) tp->edge_length = NRAND(MIN(-size, MAX(MINSIZE, MIN(tp->width, tp->height) / 2)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) tp->edge_length = MAX(MINSIZE, MIN(tp->width, tp->height) / 2); else tp->edge_length = MINSIZE; } else tp->edge_length = MIN(size, MAX(MINSIZE, MIN(tp->width, tp->height) / 2)); tp->origin.x = (tp->width / 2 + NRAND(tp->width)) / 2; tp->origin.y = (tp->height / 2 + NRAND(tp->height)) / 2; tp->fringe.n_nodes = 2; if (tp->fringe.nodes != NULL) free_penrose(tp); if (tp->fringe.nodes != NULL || tp->forced.first != 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "tp->fringe.nodes = NULL && tp->forced.first = 0\n"); } free_penrose(tp); /* Try again */ tp->done = True; } tp->forced.n_nodes = tp->forced.n_visible = 0; if ((fp = tp->fringe.nodes = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } if (fp == 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "fp = 0\n"); } if ((fp = tp->fringe.nodes = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } tp->done = True; } /* First vertex. */ fp->rule_mask = (1 << N_VERTEX_RULES) - 1; fp->list_ptr = 0; if ((fp->prev = fp->next = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } if (fp->next == 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "fp->next = 0\n"); } if ((fp->prev = fp->next = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } tp->done = True; } fp->n_tiles = 0; fp->loc = tp->origin; fp->off_screen = False; for (i = 0; i < 5; i++) fp->fived[i] = 0; /* Second vertex. */ *(fp->next) = *fp; fp->next->prev = fp->next->next = fp; fp = fp->next; i = NRAND(5); fp->fived[i] = 2 * NRAND(2) - 1; fived_to_loc(fp->fived, tp, &(fp->loc)); /* That's it! We have created our first edge. */ }