struct neighbor_list *getNeighbors(struct grid *gd, struct node *nd) { int x = nd->x; int y = nd->y; struct neighbor_list *head = new_neighbor_list(); struct neighbor_list *current = head; bool d0 = false; bool d1 = false; bool d2 = false; bool d3 = false; /* UP */ if (isWalkableAt(gd, x, y - 1)) { current = insert_right(current, &gd->nodes[y - 1][x]); d0 = d1 = true; } /* RIGHT */ if (isWalkableAt(gd, x + 1, y)) { current = insert_right(current, &gd->nodes[y][x + 1]); d1 = d2 = true; } /* DOWN */ if (isWalkableAt(gd, x, y + 1)) { current = insert_right(current, &gd->nodes[y + 1][x]); d2 = d3 = true; } /* LEFT */ if (isWalkableAt(gd, x - 1, y)) { current = insert_right(current, &gd->nodes[y][x - 1]); d3 = d0 = true; } /* UP + LEFT */ if (d0 && isWalkableAt(gd, x - 1, y - 1)) { current = insert_right(current, &gd->nodes[y - 1][x - 1]); } /* UP + RIGHT */ if (d1 && isWalkableAt(gd, x + 1, y - 1)) { current = insert_right(current, &gd->nodes[y - 1][x + 1]); } /* DOWN + RIGHT */ if (d2 && isWalkableAt(gd, x + 1, y + 1)) { current = insert_right(current, &gd->nodes[y + 1][x + 1]); } /* DOWN + LEFT */ if (d3 && isWalkableAt(gd, x - 1, y + 1)) { current = insert_right(current, &gd->nodes[y + 1][x - 1]); } return head; }
output_que() { int choice; while(1) { printf("1.Insert at right\n"); printf("2.Insert at left\n"); printf("3.Delete from left\n"); printf("4.Display\n"); printf("5.Quit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: insert_right(); break; case 2: insert_left(); break; case 3: delete_left(); break; case 4: display_queue(); break; case 5: exit(); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ }/*End of output_que() */
void add_digit(const char c) { /* if( justify == Justify::Right ) { push_right(c); } else { insert_right(c); } */ insert_right(c); }
const void *insert_node(struct s_node *node, const void *content, t_compare comp) { int comp_result; comp_result = comp(content, node->content); if (comp_result < 0) return (insert_left(node, content, comp)); else return (insert_right(node, content, comp)); }
static int search_insert(BI_S_TREE *b, struct bitree_node *node, void *data) { if (b->compare(data, node->data) > 0) { if (node->right == NULL) return insert_right(b, node, data); return search_insert(b, node->right, data); } else { if (node->left == NULL) return insert_left(b, node, data); return search_insert(b, node->left, data); } }
static void* insert( struct reinvented_avl** root, const void* key, reinvented_avl_cmp comparator, size_t payload_size, reinvented_avl_ctor constructor, _Bool* inserted) { if (!*root) { struct reinvented_avl* avl = malloc(sizeof(struct reinvented_avl) + payload_size); if (avl) { avl->height = 1; avl->left = 0; avl->right = 0; if (constructor(key, avl->payload)) { *root = avl; *inserted = 1; return avl->payload; } } free(avl); return 0; } int cmp = comparator(key, (*root)->payload); if (cmp == 0) { return (*root)->payload; } else if (cmp < 0) { return insert_left( root, key, comparator, payload_size, constructor, inserted); } else { return insert_right( root, key, comparator, payload_size, constructor, inserted); } }
void add_digit(const char c) { insert_right(c); }