# Lamport Logical Clock

### Main.h

#include “main.h”

void start(){
char v;
int l=0;
printf(“Enter the number of nodes in a graph : “);
scanf(“%d”,&n);
printf(“Enter the value of node of graph”);
for( i=0; i<n; i++)
{
scanf(“%s”,&b[i]);
}
char k=b[0];
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());
matrices[i][j]=v;
}
printf(“\n\n”);
}
for( i=0;i<n;i++)
{
l=0;
while(k!=b[l])
l++;
k=depthfirstSearch(l);
}
display();
getch();

}

int main()
{
start();
}

void display()
{
printf(” depthfirstSearch of Graph : “);
for( i=0; i<n; i++)
printf(“%c “,arr[i]);
}
void push(char val)
{
top=top+1;
stack[top]=val;
}
char pop()
{
return stack[top];
}

bool NotVisited(char val)
{
for( i=0; i<p; i++)
if(val==arr[i])
return false;
for( i=0; i<=top; i++)
if(val==stack[top])
return false;
return true;
}

char depthfirstSearch(int i)
{
int k;
char m;
if(top==-1)
{
push(b[i]);
}
m=pop();
top–;
arr[p]=m;
p++;
for( j=0; j<n; j++)
{
if(matrices[i][j]==’y’)
{
if(NotVisited(b[j]))
{
push(b[j]);
}
}
}
return stack[top];
}

# Lamport Timestamp Algorithm

### Main.h

#include “algo.h”
int timestamp(int a, int b)    //to find the maximum timestamp between two events
{
if (a>b)
return a;
else
return b;
}

int main()
{