Giter Site home page Giter Site logo

nanarow / graph-c-implementation Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 40 KB

undirected graph implementation in c using adjacency matrix

License: MIT License

C 100.00%
adjacency-matrix c circuit data-structures euler euler-circuit graph-datastructures implementation implementation-of-data-structures undirected-graph

graph-c-implementation's Introduction

Graph-C-Implementation

undirected graph implementation in c using adjacency matrix

Installation

git clone https://github.com/Nanarow/Graph-C-Implementation.git

Usage

run main.exe

main.exe

Example

graph

(1)-------(2)
   \     / 
    \   /  
     (0)   
    /   \  
   /     \ 
(4)-------(3)

example code in main function

int  main()
{
	num_vertices  =  5; //set the number of vertices
	initGraph();  // fill adjacency matrix with 0
	addEdge(0,  1);  // add edge between vertex 0 and vertex 1
	addEdge(1,  2);
	addEdge(3,  4);
	addEdge(3,  0);
	addEdge(4,  0);
	addEdge(0,  2);

	print_matrix();  // print adjacency matrix
	print_graph();  // print adjacent vertices

	findAllCircuits();  
	printAllCircuits();  

	return  0;
}

output

Adjacency matrix:
 _0_1_2_3_4_
0|0 1 1 1 1
1|1 0 1 0 0
2|1 1 0 0 0
3|1 0 0 0 1
4|1 0 0 1 0

Adjacent vertices
Vertices: 5, Edges: 6
Vertex 0 is connect to (4) Degree: 1, 2, 3, 4,
Vertex 1 is connect to (2) Degree: 0, 2,
Vertex 2 is connect to (2) Degree: 0, 1,
Vertex 3 is connect to (2) Degree: 0, 4,
Vertex 4 is connect to (2) Degree: 0, 3,

All circuits:
Circuit 1 (length 4): 0 1 2 0
Circuit 2 (length 4): 0 3 4 0
Circuit 3 (length 4): 1 0 2 1
Circuit 4 (length 4): 2 0 1 2
Circuit 5 (length 7): 3 0 1 2 0 4 3  is Euler circuit
Circuit 6 (length 7): 4 0 1 2 0 3 4  is Euler circuit

find all circuits in graph using findAllCircuits() function and print all circuits in graph using printAllCircuits() function

printAllCircuits() can check circuit that can be Euler circuit

graph-c-implementation's People

Contributors

nanarow avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.