mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-15 03:10:07 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -7,8 +7,7 @@ void printSolution(int color[]);
|
||||
|
||||
/* A utility function to check if the current color assignment
|
||||
is safe for vertex v */
|
||||
bool isSafe(int v, bool graph[V][V], int color[], int c)
|
||||
{
|
||||
bool isSafe(int v, bool graph[V][V], int color[], int c) {
|
||||
for (int i = 0; i < V; i++)
|
||||
if (graph[v][i] && c == color[i])
|
||||
return false;
|
||||
@@ -16,22 +15,18 @@ bool isSafe(int v, bool graph[V][V], int color[], int c)
|
||||
}
|
||||
|
||||
/* A recursive utility function to solve m coloring problem */
|
||||
void graphColoring(bool graph[V][V], int m, int color[], int v)
|
||||
{
|
||||
void graphColoring(bool graph[V][V], int m, int color[], int v) {
|
||||
/* base case: If all vertices are assigned a color then
|
||||
return true */
|
||||
if (v == V)
|
||||
{
|
||||
if (v == V) {
|
||||
printSolution(color);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Consider this vertex v and try different colors */
|
||||
for (int c = 1; c <= m; c++)
|
||||
{
|
||||
for (int c = 1; c <= m; c++) {
|
||||
/* Check if assignment of color c to v is fine*/
|
||||
if (isSafe(v, graph, color, c))
|
||||
{
|
||||
if (isSafe(v, graph, color, c)) {
|
||||
color[v] = c;
|
||||
|
||||
/* recur to assign colors to rest of the vertices */
|
||||
@@ -45,16 +40,14 @@ void graphColoring(bool graph[V][V], int m, int color[], int v)
|
||||
}
|
||||
|
||||
/* A utility function to print solution */
|
||||
void printSolution(int color[])
|
||||
{
|
||||
void printSolution(int color[]) {
|
||||
printf(" Following are the assigned colors \n");
|
||||
for (int i = 0; i < V; i++) printf(" %d ", color[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// driver program to test above function
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
/* Create following graph and test whether it is 3 colorable
|
||||
(3)---(2)
|
||||
| / |
|
||||
|
||||
Reference in New Issue
Block a user