void Kosaraju(GRAPH * G, stack * s) { transfer_graph(G); unsigned int temp_edge; unsigned int i; if (s->top < G->size) { printf("Graf nie jest silnie spójny!\n"); return; } while (stack_empty(s) != TRUE) { temp_edge = Pop(s); //printf("Pop:%d\n",temp_edge); if (temp_edge != 0) { stack *stacks = allocation_stack(G->size, 1); DFS_VISIT(G, temp_edge, stacks); printf("Skladowa spojnosc: "); //view_edges(G); //printf("Stack top == %d\n",stacks->top); while (stack_empty(stacks) != TRUE) { temp_edge = Pop(stacks); printf("%d ", temp_edge); delete_vertex(temp_edge, G); pop_false(temp_edge, s, G->size); } putchar('\n'); free_stack(stacks); } } }
// split a weakly connected component from the digraph // reachability by BFS t_dir_graph* t_dir_graph::split_component(){ set<t_vertex> comp = get_reachable(successors.begin()->first, true); t_dir_graph* result = get_induced_subgraph(comp); for(set<t_vertex>::const_iterator i = comp.begin(); i != comp.end(); i++) delete_vertex(*i); return result; }
void Map::delete_vertex(vertex_t *vertex) { for (int a = 0; a < n_verts; a++) { if (verts[a] == vertex) { delete_vertex(a); return; } } }
int main() { int source,destination,ver; char option; v_node *head=NULL; while(1) { system("cls"); printf("\t\t\t\tAdjacency List Implementation\n\n"); printf("Choose Option :-\n\n1 - Insert Vertex\n2 - Insert Edge\n3 - Delete Edge\n4 - Delete Vertex\n5 - Display\n\tBackspace - Exit\n"); option = getch(); system("cls"); switch(option) { case '1': printf("\t\t\t\tHere you can insert vertex\n\n"); printf("Enter vertex to be inserted : "); scanf("%d",&ver); head=insert_vertex(head,ver); hold_screen(); break; case '2': printf("\t\t\t\tHere you can insert an edge\n\n"); printf("Enter source : "); scanf("%d",&source); printf("Enter destination : "); scanf("%d",&destination); insert_edge(head,source,destination); hold_screen(); break; case '3': printf("\t\t\t\tHere you can delete an edge\n\n"); printf("Enter source : "); scanf("%d",&source); printf("Enter destination : "); scanf("%d",&destination); delete_edge(head,source,destination); hold_screen(); break; case '4': printf("Enter vertex to be deleted : "); scanf("%d",&ver); head=delete_vertex(head,ver); hold_screen(); break; case '5': display(head); hold_screen(); break; case 8: return 0; } } }
void Map::v_merge(int v1, int v2) { for (DWORD l = 0; l < n_lines; l++) { if (lines[l]->vertex1 == v1) lines[l]->vertex1 = v2; else if (lines[l]->vertex2 == v1) lines[l]->vertex2 = v2; } delete_vertex(v1); }
// delete all vertices that are not in the given vertex set from the graph void t_dir_graph::induced_subgraph(const set<t_vertex>& vertices){ set<t_vertex> v = set_substract(get_vertices(), vertices); for(set<t_vertex>::const_iterator i = v.begin(); i != v.end(); i++) delete_vertex(*i); }
// keys_edit: Keys for the 2d editor // ------------------------------ >> void keys_edit() { if (!map.opened) return; // Scroll up if (binds.pressed("view_up")) { yoff += ((MAJOR_UNIT / (int)zoom)) + 1; force_map_redraw(true, true); } // Scroll down if (binds.pressed("view_down")) { yoff -= ((MAJOR_UNIT / (int)zoom)) + 1; force_map_redraw(true, true); } // Scroll left if (binds.pressed("view_left")) { xoff += ((MAJOR_UNIT / (int)zoom)) + 1; force_map_redraw(true, true); } // Scroll right if (binds.pressed("view_right")) { xoff -= ((MAJOR_UNIT / (int)zoom)) + 1; force_map_redraw(true, true); } // Zoom in if (binds.pressed("view_zoomin")) view_zoom(true); // Zoom out if (binds.pressed("view_zoomout")) view_zoom(false); // Center view on mouse if (binds.pressed("view_mousecenter")) { xoff = -m_x(mouse.x) / MAJOR_UNIT; yoff = -m_y(mouse.y) / MAJOR_UNIT; force_map_redraw(true, true); } // Set offsets to 0, 0 if (binds.pressed("view_origin")) { xoff = yoff = 0; force_map_redraw(true, true); } // Vertices mode if (binds.pressed("mode_vertices")) change_edit_mode(0); // Linedefs mode if (binds.pressed("mode_linedefs")) change_edit_mode(1); // Sectors mode if (binds.pressed("mode_sectors")) change_edit_mode(2); // Things mode if (binds.pressed("mode_things")) change_edit_mode(3); // Change mode if (binds.pressed("mode_change")) cycle_edit_mode(); // Increase grid size if (binds.pressed("view_increasegrid")) { increase_grid(); force_map_redraw(false, true); } // Decrease grid size if (binds.pressed("view_decreasegrid")) { decrease_grid(); force_map_redraw(false, true); } // Clear selection if (binds.pressed("edit_clearselection")) { clear_selection(); force_map_redraw(true); } // Delete item if (binds.pressed("edit_deleteitem")) { if (edit_mode == 0) delete_vertex(); if (edit_mode == 1) delete_line(); if (edit_mode == 2) delete_sector(); if (edit_mode == 3) delete_thing(); force_map_redraw(true); } // Create item if (binds.pressed("edit_createitem")) { if (edit_mode == 0) { if (!selection()) create_vertex(); else create_lines(false); force_map_redraw(true); return; } if (edit_mode == 1) { if (selection()) create_sector(); force_map_redraw(true); return; } if (edit_mode == 3) { create_thing(); force_map_redraw(true); return; } binds.clear("edit_createitem"); } // Sector height quick changes (8 units) if (binds.pressed("sector_upfloor8")) { if (edit_mode == 2) sector_changeheight(true, 8); } if (binds.pressed("sector_downfloor8")) { if (edit_mode == 2) sector_changeheight(true, -8); } if (binds.pressed("sector_upceil8")) { if (edit_mode == 2) sector_changeheight(false, 8); } if (binds.pressed("sector_downceil8")) { if (edit_mode == 2) sector_changeheight(false, -8); } if (binds.pressed("sector_upboth8")) { if (edit_mode == 2) { sector_changeheight(true, 8); sector_changeheight(false, 8); } } if (binds.pressed("sector_downboth8")) { if (edit_mode == 2) { sector_changeheight(true, -8); sector_changeheight(false, -8); } } // Sector height quick changes (1 unit) if (binds.pressed("sector_upfloor")) { if (edit_mode == 2) sector_changeheight(true, 1); } if (binds.pressed("sector_downfloor")) { if (edit_mode == 2) sector_changeheight(true, -1); } if (binds.pressed("sector_upceil")) { if (edit_mode == 2) sector_changeheight(false, 1); } if (binds.pressed("sector_downceil")) { if (edit_mode == 2) sector_changeheight(false, -1); } if (binds.pressed("sector_upboth")) { if (edit_mode == 2) { sector_changeheight(true, 1); sector_changeheight(false, 1); } } if (binds.pressed("sector_downboth")) { if (edit_mode == 2) { sector_changeheight(true, -1); sector_changeheight(false, -1); } } // Flip line if (binds.pressed("line_flip")) { if (edit_mode == 1) line_flip(true, false); force_map_redraw(true); } // Swap line sides if (binds.pressed("line_swapsides")) { if (edit_mode == 1) line_flip(false, true); force_map_redraw(true); } // Flip both line direction and sides if (binds.pressed("line_flipboth")) { if (edit_mode == 1) line_flip(true, true); force_map_redraw(true); } // Begin line draw if (binds.pressed("line_begindraw")) { if (!line_draw) line_draw = true; binds.clear("line_begindraw"); } // Begin rectangle draw if (binds.pressed("line_begindraw_rect")) { if (!line_draw) { line_draw = true; sel_box.set(mouse.x, mouse.y, mouse.x, mouse.y); } binds.clear("line_begindraw_rect"); } // Undo if (binds.pressed("edit_undo")) { undo(); clear_selection(); hilight_item = -1; force_map_redraw(true, true); //map_changelevel(3); map.change_level(MC_NODE_REBUILD); binds.clear("edit_undo"); } // Edit item if (binds.pressed("edit_edititem")) { edit_item(); binds.clear("edit_edititem"); } // Merge sectors if (binds.pressed("sector_merge")) { sector_merge(false); binds.clear("sector_merge"); } // Join sectors if (binds.pressed("sector_join")) { sector_merge(true); binds.clear("sector_join"); } if (binds.pressed("view_3dmode")) { binds.clear("view_3dmode"); binds.clear("3d_exit"); start_3d_mode(); } if (binds.pressed("open_console")) { binds.clear("open_console"); popup_console(); } if (binds.pressed("copy")) { binds.clear("copy"); clipboard.Copy(); } if (binds.pressed("paste")) { binds.clear("paste"); paste_mode = true; clear_selection(); } if (binds.pressed("cancel_paste")) { binds.clear("cancel_paste"); paste_mode = false; force_map_redraw(true, false); } }
/*- * Add a tile described by vtype to the side of vertex. This must be * allowed by the rules -- we do not check it here. New vertices are * allocated as necessary. The fringe and the forced vertex pool are updated. * The new tile is drawn on the display. * * One thing we do check here is whether the new tile causes an untiled * area to become enclosed by the tiling. If this would happen, the tile * is not added. The return value is true iff a tile was added. */ static int add_tile(ModeInfo * mi, fringe_node_c * vertex, unsigned side, vertex_type_c vtype) { tiling_c *tp = &tilings[MI_SCREEN(mi)]; fringe_node_c *left = (fringe_node_c *) NULL, *right = (fringe_node_c *) NULL, *far = (fringe_node_c *) NULL, *node; unsigned fc = fringe_changes(mi, vertex, side, vtype, &right, &far, &left); vertex_type_c ltype = VT_LEFT(vtype), rtype = VT_RIGHT(vtype), ftype = VT_FAR(vtype); /* By our conventions vertex->next lies to the left of vertex and vertex->prev to the right. */ /* This should never occur. */ if (fc & FC_BAG) { tp->done = True; if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in add_tile()\n"); (void) fprintf(stderr, "fc = %d, FC_BAG = %d\n", fc, FC_BAG); } } if (side == S_LEFT) { if (right == NULL) if ((right = alloc_vertex(mi, vertex_dir(mi, vertex, S_LEFT) - vtype_angle(vtype), vertex, tp)) == NULL) return False; if (far == NULL) if ((far = alloc_vertex(mi, vertex_dir(mi, left, S_RIGHT) + vtype_angle(ltype), left, tp)) == NULL) return False; } else { if (left == NULL) if ((left = alloc_vertex(mi, vertex_dir(mi, vertex, S_RIGHT) + vtype_angle(vtype), vertex, tp)) == NULL) return False; if (far == NULL) if ((far = alloc_vertex(mi, vertex_dir(mi, right, S_LEFT) - vtype_angle(rtype), right, tp)) == NULL) return False; } /* Having allocated the new vertices, but before joining them with the rest of the fringe, check if vertices with same coordinates already exist. If any such are found, give up. */ node = tp->fringe.nodes; do { if (((fc & FC_NEW_LEFT) && fived_equal(node->fived, left->fived)) || ((fc & FC_NEW_RIGHT) && fived_equal(node->fived, right->fived)) || ((fc & FC_NEW_FAR) && fived_equal(node->fived, far->fived))) { /* Better luck next time. */ if (fc & FC_NEW_LEFT) delete_vertex(mi, left, tp); if (fc & FC_NEW_RIGHT) delete_vertex(mi, right, tp); if (fc & FC_NEW_FAR) delete_vertex(mi, far, tp); return False; } node = node->next; } while (node != tp->fringe.nodes); /* Rechain. */ if (!(fc & FC_CUT_THIS)) { if (side == S_LEFT) { vertex->next = right; right->prev = vertex; } else { vertex->prev = left; left->next = vertex; } } if (!(fc & FC_CUT_FAR)) { if (!(fc & FC_CUT_LEFT)) { far->next = left; left->prev = far; } if (!(fc & FC_CUT_RIGHT)) { far->prev = right; right->next = far; } } draw_tile(vertex, right, far, left, vtype, mi); /* Delete vertices that are no longer on the fringe. Check the others. */ if (fc & FC_CUT_THIS) { tp->fringe.nodes = far; delete_vertex(mi, vertex, tp); } else { add_vtype(vertex, side, vtype); check_vertex(mi, vertex, tp); tp->fringe.nodes = vertex; } if (fc & FC_CUT_FAR) delete_vertex(mi, far, tp); else { add_vtype(far, fc & FC_CUT_RIGHT ? S_LEFT : S_RIGHT, ftype); check_vertex(mi, far, tp); } if (fc & FC_CUT_LEFT) delete_vertex(mi, left, tp); else { add_vtype(left, fc & FC_CUT_FAR ? S_LEFT : S_RIGHT, ltype); check_vertex(mi, left, tp); } if (fc & FC_CUT_RIGHT) delete_vertex(mi, right, tp); else { add_vtype(right, fc & FC_CUT_FAR ? S_RIGHT : S_LEFT, rtype); check_vertex(mi, right, tp); } return True; }