Showing posts with label Euler Cycle. Show all posts
Showing posts with label Euler Cycle. Show all posts

Saturday, April 18, 2015

C Program for Fleury's Algorithm to find euler circuit


EULER CIRCUIT PROBLEM

Consider the three figures in Figure below. A popular puzzle is to reconstruct these figures using a pen, drawing each line exactly once. The pen may not be lifted from the paper while the drawing is being performed. As an extra challenge, make the pen finish at the same point at which it started. This puzzle has a surprisingly simple solution.

The first figure can be drawn only if the starting point is the lower left- or right-hand corner, and it is not possible to finish at the starting point. The second figure is easily drawn with the finishing point the same as the starting point, but the third figure cannot be drawn at all within the parameters of the puzzle.
             We can convert this problem to a graph theory problem by assigning a vertex to each intersection.Then the edges can be assigned in the natural manner, as shown in below.
After this conversion is performed, we must find a path in the graph that visits every edge exactly once. If we are to solve the "extra challenge," then we must find a cycle that visits every edge exactly once. This graph problem was solved in 1736 by Euler and marked the beginning of graph theory. The problem is thus commonly referred to as an Euler path (sometimes Euler touror Euler circuit problem, depending on the specific problem statement. The Euler tour and Euler circuit problems, though slightly different, have the same basic solution. Thus, we will consider the Euler circuit problem

EULER PATH
In graph theory Euler path is a path that visits each node from the graph exactly once.
EULER CYCLE/EULER CIRCUIT
            Euler cycle is a Euler path that starts and ends with the same node.
EULER GRAPH
            Euler graph is a graph with graph which contains Euler cycle.
EULERS THEOREM
Connected undirected graph is Euler graph if and only if every node in the graph is of even degree (has even number of  edges starting from that node).

Fleury's Algorithm.

1. Pick up a starting Vertex.
    Condition 1: If all Nodes have even degree, there should be a euler Circuit/Cycle. We can pick up any vertex as starting vertex.
    Condition 2: If exactly 2 nodes have odd degree, there should be euler path. We need to pick up any one of this two as starting vertex.
    Condition 3: If more than 2 nodes or exactly one node have odd degree, euler path/circuit not possible.
2. Get the next vertex in euler Path.
    Condition: Don't break the bridge.
        i) select the next vertex which has more than one edges.
        ii) If next vertex has only one edge,
            a) If it is last vertex, We can choose it as next vertex.
            b) otherwise dont.
3. Remove the selected edge.
4. Repeat 2 & 3 until all edges have been traversed, and you are back at the starting vertex.





















C Program::


#include<stdio.h>
#include<conio.h>

int n;
int b[100],finalPath[100];
char ajMat[100][100];
int fp=0,count=0;

//Display the Euler circuit/path
void displayPath()
{
     int i;
     for(i=0;i<fp;i++)
     {
       printf("%d ->",finalPath[i]);
     }
}

//To get the degree of node i.e no of edges currently connected to the node
int getDegree(int node)
{
    int j,deg=0;
    int pos=getIndex(node);
    for(j=0;j<n;j++)
    {
      if(ajMat[pos][j]=='y') deg++;
    }
    return deg;
}

//To assign the root of the graph
//Condition 1: If all Nodes have even degree, there should be a euler Circuit/Cycle
//We can start path from any node
//Condition 2: If exactly 2 nodes have odd degree, there should be euler path.
//We must start from node which has odd degree
//Condition 3: If more than 2 nodes or exactly one node have odd degree, euler path/circuit not possible.


//findRoot() will return 0 if euler path/circuit not possible
//otherwise it will return array index of any node as root

int findRoot()
{
    
     int i,cur=1;//Assume root as 1
     for(i=0;i<n;i++)
     {
        if(getDegree(b[i])%2!=0)
        {
           count++;
           cur=i;//Store the node which has odd degree to cur variable
        }
     }
     //If count is not exactly 2 then euler path/circuit not possible so return 0
     if(count!=0 && count!=2)
     {
        return 0;
     }
     else return b[cur];// if exactly 2 nodes have odd degree, it will return one of those node as root otherwise return 1 as root  as assumed
}

//To get the current index of node in the array b[] of nodes
int getIndex(int node)
{
    int k=0;
    while(node!=b[k])
    k++;
     //printf("inside while\n");
   
    //l++;
    return k;
}

int isLastNode(int node)
{
    int i=0;
    int degSum=0;
    for(i=0;i<n;i++)
    {
     degSum=degSum+getDegree(b[i]);
    }
    if(degSum==2)
      return 1;
    else
      return 0;
}

int getNextNode(int node)
{
    int i=0;
    int pos=getIndex(node);
        
    for(i=0;i<n;i++)
    {   
      if(ajMat[pos][i]=='y')
      {        
        if(!isHasOneEdge(b[i]))
        {
          return b[i];
        }
        else
        {
            if(isLastNode(b[i]))
            return b[i];
        }
      }
    }
    return -1;
}

int isHasOneEdge(int node)
{  
    if(getDegree(node)==1)
      return 1;
    else
      return 0;
}

int isCompleted()
{
    int i=0;
    for(i=0;i<n;i++)
    {
        if(getDegree(b[i])>0)
             return 0;
    }
    return 1;
}

void removeEdge(root,eNode)
{
     int pos1=0,pos2=0;    
     pos1=getIndex(root);
     pos2=getIndex(eNode);
     ajMat[pos1][pos2]='n';
     ajMat[pos2][pos1]='n';
}

//To find the Euler circuit/path and store it in finalPath[] array
void eularFind(int root)
{   
     int eNode;
     while(!isCompleted())
     {
        eNode=getNextNode(root);   //get Next node    
        finalPath[fp++]=eNode;     //add the node to euler path
        removeEdge(root,eNode);   //remove the edge
        root=eNode; //change the root
     }
    /* printf("root=%d\n",root);
        eNode=getNextNode(root);
        printf("getNextNode=%d \n",eNode);
        finalPath[fp++]=eNode;
        removeEdge(root,eNode);
        root=eNode;*/
}

void printbArray()
{
     int i;
      for( i=0; i<n; i++)
    {
     printf("%d  ",b[i]);//store the nodes in b[] array
    }
}
int main()
{
    char v;
    int i,j,l;
    printf("Enter the number of nodes in a graph\n");
    scanf("%d",&n);
    printf("Enter the value of node of graph\n");
    for( i=0; i<n; i++)
    {
     scanf("%d",&b[i]);//store the nodes in b[] array
    }
  
   
    //Get the Graph details by using adjacency matrix
    printf("Enter the value in adjancency matrix in form of 'Y' or 'N'\n");
    printf("\nIf there is an edge between the two vertices then enter 'Y' else 'N'\n");
    for( i=0; i<n; i++)
    printf(" %d ",b[i]);
    for( i=0;i<n; i++)
    {
     printf("\n%d ",b[i]);
     for( j=0; j<n; j++)
     {
      printf("%c ",v=getch());
      ajMat[i][j]=v;
     }
      printf("\n\n");
    }
  
/*   We can manually hard code the Graph value by below. But u need to command the above one to get the edge details.
ajMat[0][0]='n';
ajMat[0][1]='y';
ajMat[0][2]='n';
ajMat[0][3]='y';
ajMat[0][4]='n';
ajMat[0][5]='n';
           
ajMat[1][0]='y';
ajMat[1][1]='n';
ajMat[1][2]='y';
ajMat[1][3]='n';
ajMat[1][4]='y';
ajMat[1][5]='y';
           
ajMat[2][0]='n';
ajMat[2][1]='y';
ajMat[2][2]='n';
ajMat[2][3]='y';
ajMat[2][4]='y';
ajMat[2][5]='y';
           
ajMat[3][0]='y';
ajMat[3][1]='n';
ajMat[3][2]='y';
ajMat[3][3]='n';
ajMat[3][4]='n';
ajMat[3][5]='n';
           
ajMat[4][0]='n';
ajMat[4][1]='y';
ajMat[4][2]='y';
ajMat[4][3]='n';
ajMat[4][4]='n';
ajMat[4][5]='n';
           
ajMat[5][0]='n';
ajMat[5][1]='y';
ajMat[5][2]='y';
ajMat[5][3]='n';
ajMat[5][4]='n';
ajMat[5][5]='n';
 */ 
    //findRoot() will return 0 if euler path/circuit not possible
    //otherwise it will return array index of any node as root

    int root,pos;
    if(root=findRoot())
    {
      if(count) printf("Available Euler Path is\n");
      else printf("Available Euler Circuit is\n");
      finalPath[fp++]=root;
      eularFind(root);
      displayPath();
    }
    else printf("Euler path or circuit not available\n");
    getch();
}


Goto Data Structure Concepts

Saturday, November 22, 2014

C# program to find Euler path or Euler Circuit


Please Go through the Introduction of Euler Circuit/Path to understand the Logic.

EulerCircuit is the Class which contains following Methods.


1. void GetInput()
2. int FindRoot()
3. int GetIndex(char c)
4. Boolean AllVisited(int node)
5. void FindEuler(int root)
6. int GetDegree(int i)
7. void FindEulerCircuit()


1. void GetInput()


  • Get the no of nodes/vertices in Graph and store it in variable total.
  • Get the names of all nodes/vertices and store it in nodeList array.
  • Get the Graph edge representation and store it in 2 dimensional array GraphMatrix.
  • If there is an edge between the two vertices then enter 'y' else 'n'



2. int FindRoot()


  • It will return 0 or 1 or any number.
  • Return 0 means: Euler path or circuit not possible for given graph.
  • Return 1 means: Euler circuit  available.
  • Return any other nunmber means: Euler path available.
  • GetDegree method used to find the no of edges connected to a node/vertex
  • To assign the root of the graph

Condition 1: If all Nodes have even degree, there should be a euler Circuit/Cycle.We can start path from any node. return 1.
Condition 2: If exactly 2 nodes have odd degree, there should be euler path.We must start from node which has odd degree. return any other no.
Condition 3: If more than 2 nodes or exactly one node have odd degree, euler path/circuit not possible. return 0.    


3. int GetIndex(char c)


  • It will return the index of the node/vertex(c) in nodeList array.



4. Boolean AllVisited(int node)


  • It will return true or false
  • Return true means: All edges connected to node/vertex are already visited
  • Return false means: there is at-least 1 edge connected to node/vertex not yet visited.



5. void FindEuler(int root)


  • Find the Euler circuit/path with starting point as root and store it in finalPath arrayList
  • push root into the stack tempPath
  • If all adjacent nodes are already visited
  • pop element from stack and store it in finalpath arrayList
  • If any unvisited node available push that node into stack
  •         mark that edge as already visited by marking 'n' in GraphMatrix[][]
  •         break the iteration
  • Loop will end when stack becomes empty.



6.int GetDegree(int i)


  • Return the number of edges connected to vertex at index i of nodeList array



7.void FindEulerCircuit()



  • GetInput();
  • root = FindRoot()//Decide the root.
  • if(root!=0)
  • FindEuler(root)//Find the euler path/cycle with starting point as root
  • PrintEulerCircuit()//Print the euler circuit/path.
  • else euler path/circuit not possible.

C# Program::


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Euler_Circuit_Application
{
    class EulerCircuit
    {
        Stack tempPath = new Stack();
        ArrayList finalPath = new ArrayList();//to store the final path
        char[] nodeList;//to store the nodes
        char[,] GraphMatrix;//to store the edge representation of Graph
        int total, count;//total->total no of nodes, count->no of even degree node
        //To Get the all input from user
        private void GetInput()
        {
            Console.WriteLine("Enter the number of Nodes");
            try
            {//Get the number of nodes in a Graph
                total = int.Parse(Console.ReadLine());
                GraphMatrix = new char[total, total];
                nodeList = new char[total];               

                Console.WriteLine("Enter the Nodes");
                //To get the node/vertices to nodeList array
                for (int i = 0; i < total; i++)
                {                    
                    nodeList[i] = char.Parse(Console.ReadLine());
                }

                Console.WriteLine("Enter the Graph representattion in Matrix");
                Console.WriteLine("If there is an edge between the two vertices then enter 'y' else 'n'");             
                //To get the edge details in a Graph
                for (int i = 0; i < total; i++)
                {
                   
                    for (int j = 0; j < total; j++)
                    {
                        Console.Write("{0}----{1}==> ",nodeList[i],nodeList[j]);
                        GraphMatrix[i, j] = char.Parse(Console.ReadLine());                        
                    }
                    Console.WriteLine("");
                }
            }
            catch
            {
                Console.WriteLine("Invalid number");
            }
        }

        //To get the number of edges connected to vertex at index i of nodeList array
        private int GetDegree(int i)
        {
            int j, deg = 0;
            for (j = 0; j < total; j++)
            {
                if (GraphMatrix[i,j] == 'y') deg++;
            }
            return deg;
        }
        //To assign the root of the graph
        //Condition 1: If all Nodes have even degree, there should be a euler Circuit/Cycle
        //We can start path from any node
        //Condition 2: If exactly 2 nodes have odd degree, there should be euler path.
        //We must start from node which has odd degree
        //Condition 3: If more than 2 nodes or exactly one node have odd degree, 
        //euler path/circuit not possible.

        //findRoot() will return 0 if euler path/circuit not possible
        //otherwise it will return array index of any node as root
        private int FindRoot()
        {
            int root = 1; //Assume root as 1
            count = 0;
            for (int i = 0; i < total; i++)
            {
                if (GetDegree(i) % 2 != 0)
                {
                    count++;
                    root = i;//Store the node which has odd degree to root variable
                }
            }
            //If count is not exactly 2 then euler path/circuit not possible so return 0
            if (count != 0 && count != 2)
            {
                return 0;
            }
            else return root;// if exactly 2 nodes have odd degree, 
            //it will return one of those node as root otherwise return 1 as root  as assumed
        }

        //To get the current index of node in the array nodeList[] of nodes
        private int GetIndex(char c)
        {
            int index = 0;
            while (c != nodeList[index])
                index++;
            return index;
        }

        //To check weather all adjecent vertices/nodes are visited or not
        
        private Boolean AllVisited(int node)
        {            
            for (int l = 0; l < total; l++)
            {
                if (GraphMatrix[node, l] == 'y')
                    return false;
            }
            return true;
        }

        //To find the Euler circuit/path and store it in finalPath arrayList
        private void FindEuler(int root)
        {
            int ind;
            tempPath.Clear();
            //push root into the stack
            tempPath.Push(nodeList[root]);
            while(tempPath.Count!=0)//until Stack going to empty
            {
                //get the array index of top of the stack
                ind = GetIndex((char)tempPath.Peek());                
                if (AllVisited(ind))
                {
                    //If all adjacent nodes are already visited
                    //pop element from stack and store it in finalpath arrayList
                    finalPath.Add(tempPath.Pop());
                }
                else
                {
                    //If any unvisited node available push that node into stack
                    //mark that edge as already visited by marking 'n' in GraphMatrix[][]
                    //break the iteration
                    for (int j = 0; j < total; j++)
                    {
                        if (GraphMatrix[ind,j] == 'y')
                        {
                            GraphMatrix[ind, j] = 'n';
                            GraphMatrix[j, ind] = 'n';
                            tempPath.Push(nodeList[j]);
                            break;
                        }
                    }
                }
            }
        }

        //THis is the Main Program
        public void FindEulerCircuit()
        {
            //Get the Graph representation from user
            GetInput();
            //Decide the root
            int root = FindRoot();
            //findRoot() will return 0 if euler path/circuit not possible
            //otherwise it will return array index of any node as root
            if(root!=0)
            {
              if(count!=0) Console.WriteLine("Available Euler Path is");
              else  Console.WriteLine("Available Euler circuit is");
                //Find the Euler circuit
              FindEuler(root);
                //Print the euler Circuit
              PrintEulerCircuit();
            }
            else
            {
                Console.WriteLine("Euler Path or Circuit not Possible");
            }           
            
        }

        public void PrintEulerCircuit()
        {
            for (int i = 0; i < finalPath.Count;i++ )
            {
                Console.Write("{0}--->", finalPath[i]);
            }
        }
    }

    class ExecuteEulerCircuit
    {
        static void Main(string[] args)
        {          
            //Create oblect for EulerCircuit class and call FindEulerCircuit()
            EulerCircuit ec = new EulerCircuit();
            ec.FindEulerCircuit();           

            Console.ReadKey();
        }
    }
}



Example 1:Input Graph



Output:



Example 2:Input Graph:



Output::



Example 3:: Input Graph:


Output::






Saturday, October 26, 2013

C program to find Euler path or Euler Circuit


Reason to write this


            I was searched for C program to find the euler path/circuit in Google, but I am not able to find any C implementation for this. So I have decided to write a C program to find euler path/circuit. I written, compiled and published here. I hope it will helpful for some persons like me who are looking for C program to find the euler path/circuit.

EULER CIRCUIT PROBLEM

Consider the three figures in Figure below. A popular puzzle is to reconstruct these figures using a pen, drawing each line exactly once. The pen may not be lifted from the paper while the drawing is being performed. As an extra challenge, make the pen finish at the same point at which it started. This puzzle has a surprisingly simple solution.

The first figure can be drawn only if the starting point is the lower left- or right-hand corner, and it is not possible to finish at the starting point. The second figure is easily drawn with the finishing point the same as the starting point, but the third figure cannot be drawn at all within the parameters of the puzzle.
             We can convert this problem to a graph theory problem by assigning a vertex to each intersection.Then the edges can be assigned in the natural manner, as shown in below.
After this conversion is performed, we must find a path in the graph that visits every edge exactly once. If we are to solve the "extra challenge," then we must find a cycle that visits every edge exactly once. This graph problem was solved in 1736 by Euler and marked the beginning of graph theory. The problem is thus commonly referred to as an Euler path (sometimes Euler touror Euler circuit problem, depending on the specific problem statement. The Euler tour and Euler circuit problems, though slightly different, have the same basic solution. Thus, we will consider the Euler circuit problem

EULER PATH
In graph theory Euler path is a path that visits each edge from the graph exactly once.
EULER CYCLE/EULER CIRCUIT
            Euler cycle is a Euler path that starts and ends with the same node.
EULER GRAPH
            Euler graph is a graph with graph which contains Euler cycle.
EULERS THEOREM
Connected undirected graph is Euler graph if and only if every node in the graph is of even degree (has even number of  edges starting from that node).

HIERHOLZER’S ALGORITHM
This is an algorithm to find an Eulerian circuit in a connected graph in which every vertex has even degree.
1. Choose any vertex v and push it onto a stack. Initially all edges are unmarked.
2. While the stack is nonempty, look at the top vertex, u, on the stack. If u has an unmarked incident edge, say, to a vertex w, then push w onto the stack and mark the edge uw. On the other hand, if u has no unmarked incident edge, then pop u off the stack and print it.                
                 When the stack is empty, you will have printed a sequence of vertices that correspond to an Eulerian circuit

HIERHOLZER’S ALGORITHM - Example
We will use two stacks in this example: tempPath and finalPath in order to be able to combine the simple cycles we’ve found into one big cycle (the searched Euler’s cycle).

1.Lets start with edge 0 (arbitrary choice)
Adding 0 to the tempPath stack.
tempPath:0
finalPath:<empty>
2.Lets choose edge  0->1 (arbitrary choice).
Erasing the edge and adding 1 to tempPath stack
tempPath:0 1
finalPath:<empty>


3.Lets choose edge  1->2 (arbitrary choice).
Erasing the edge and adding 2 to tempPath stack
tempPath:0 1 2
finalPath:<empty>
4.Lets choose edge  2->3 (arbitrary choice).

Erasing the edge and adding 3 to tempPath stack
tempPath:0 1 2 3
finalPath:<empty>
5.Lets choose edge  3->0 (only possible choice).

Erasing the edge and adding 0 to tempPath stack
tempPath:0 1 2 3 0
finalPath:<empty>
We’ve created a simple cycle and there is nowhere to go, but there are still unvisited edges! Go back to vertex with unvisited edge, moving elements from tempPath to finalPath.

tempPath:0 1 2 3 0
finalPath:<empty>
6.Move back from o to 3.
Move o from tempPath to finalPath.
tempPath:0 1 2 3
finalPath:0
7.Move back from 3 to 2.

Move 3 from tempPath to finalPath.
tempPath:0 1 2
finalPath:0 3
8.Lets choose edge  2->4 (arbitrary choice).

Erasing the edge and adding 4 to tempPath stack
tempPath:0 1 2 4
finalPath:0 3
9.Lets choose edge  4->1 (only possible choice).

Erasing the edge and adding 1 to tempPath stack
tempPath:0 1 2 4 1
finalPath:0 3
10.Lets choose edge  1->5 (only possible choice).

Erasing the edge and adding 5 to tempPath stack
tempPath:0 1 2 4 1 5
finalPath:0 3
11.Lets choose edge  5->2 (only possible choice).

Erasing the edge and adding 2 to tempPath stack
tempPath:0 1 2 4 1 5 2
finalPath:0 3
So we have passed through all the edges! Now all we have to do is move elements from tempPath stack to finalPath stack!

tempPath:0 1 2 4 1 5 2
finalPath:0 3
The result sequence in finalPath stack is an Euler’s cycle!

tempPath:0 1 2 4 1 5 2         
finalPath:0 3
to
tempPath:<empty>
finalPath:0 3 2 5 1 4 2 1 0

C Program to find EULER Circuit/ EULER Path using Hierholzer’s Algorithm  


//Written and Compiled by M.Karuppasamy Pandiyan
#include<stdio.h>
#include<conio.h>
char stack[20];
int top=-1, n;
char b[20],finalPath[20];
char ajMat[20][20];
int fp=0,count;

//Push into Stack Operation
void push(char val)
{
top=top+1;
stack[top]=val;
}

//Pop from Stack Operation
char pop()
{
return stack[top--];
}

//To check weather all adjecent vertices/nodes are visited 
//or not
int allVisited(int i)
{
    int j;
    for(j=0;j<n;j++)
    {
       if(ajMat[i][j]=='y')
       return 0;
    }
    return 1;
}

//To get the current index of node in the array b[] of nodes
int getNo(char c)
{
    int l=0;
    while(c!=b[l])
    l++;
    return l;

}

//Display the Euler circuit/path
void displayPath()
{
     int i;
     for(i=0;i<fp;i++)
     {
       printf("%c ->",finalPath[i]);
     }
}

//To find the Euler circuit/path and store it in finalPath[] array
void eularFind(int root)
{
     int l,j;
     //push root into the stack
    push(b[root]);
    //Run upto stock becomes empty i.e top=-1
    while(top!=-1)
    {
      
      //get the array index of top of the stack
      l=getNo(stack[top]);
      //If all adjacent nodes are already visited
      //pop element from stack and store it in finalpath[] array
      if(allVisited(l))
      {
        finalPath[fp++]=pop();
        
      }
      //If any unvisited node available push that node into stack
      //mark that edge as already visited by marking 'n' in adjMat[][]
      //break the iteration
      else
      {
        for(j=0;j<n;j++)
        {
        if(ajMat[l][j]=='y')
        {
            
             ajMat[l][j]='n';
             ajMat[j][l]='n';
             push(b[j]);
            
             break;
           
        }
        }
       }
     }
}

//To get the degree of node i.e no of edges currently connected to the node
int getDegree(int i)
{
    int j,deg=0;
    for(j=0;j<n;j++)
    {
      if(ajMat[i][j]=='y') deg++;
    }
    return deg;
}

//To assign the root of the graph
//Condition 1: If all Nodes have even degree, there should be a euler Circuit/Cycle
//We can start path from any node
//Condition 2: If exactly 2 nodes have odd degree, there should be euler path.
//We must start from node which has odd degree
//Condition 3: If more than 2 nodes or exactly one node have odd degree, euler path/circuit not possible.

//findRoot() will return 0 if euler path/circuit not possible
//otherwise it will return array index of any node as root
int findRoot()
{
     
     int i,cur=1;//Assume root as 1
     for(i=0;i<n;i++)
     {
        if(getDegree(i)%2!=0)
        {
           count++;
           cur=i;//Store the node which has odd degree to cur variable
        }
     }
     //If count is not exactly 2 then euler path/circuit not possible so return 0
     if(count!=0 && count!=2)
     {
        return 0;
     }
     else return cur;// if exactly 2 nodes have odd degree, it will return one of those node as root otherwise return 1 as root  as assumed
}

int main()
{
    char v;
    int i,j,l;
    printf("Enter the number of nodes in a graph\n");
    scanf("%d",&n);
    printf("Enter the value of node of graph\n");
    for( i=0; i<n; i++)
    {
     scanf("%s",&b[i]);//store the nodes in b[] array
    }
    
    //Get the Graph details by using adjacency matrix
    printf("Enter the value in adjancency matrix in from of 'Y' or 'N'\n");
    printf("\nIf there is an edge between the two vertices then enter 'Y' or 'N'\n");
    for( i=0; i<n; i++)
    printf(" %c ",b[i]);
    for( i=0;i<n; i++)
    {
     printf("\n%c ",b[i]);
     for( j=0; j<n; j++)
     {
      printf("%c ",v=getch());
      ajMat[i][j]=v;
     }
      printf("\n\n");
    }
    
//findRoot() will return 0 if euler path/circuit not possible
//otherwise it will return array index of any node as root
    int root;
    if(root=findRoot())
    {
      if(count) printf("Available Euler Path is\n");
      else printf("Available Euler Circuit is\n");
      eularFind(root);
      displayPath();
    }
    else printf("Euler path or circuit not available\n");
    getch();
}

Example1: Input  Graph
Output
Example2: Input  Graph
Output:

Exmple 3:Input Graph
Output:






Reference:
       1. Data Structures and Algorithm Analysis in C by Mark Allen Weiss.
       2. Euler Graphs Power point Presentation by Deyan Yosifov, Telerik Corporation.

Goto Data Structure Concepts