Wednesday 9 March 2016

Vector clock

#include<stdio.h>
#include<conio.h>
struct node{
int x;int y;int z;
}p1[5],p2[5],p3[5];



int main()
{int i,p,a[5],b[5],c[5],d[5];
printf("enter number of events");

scanf("%d",&p);
for(i=0;i<p;i++)
{
printf(" %d event is from e ",i+1);
scanf("%d %d",&a[0],&b[0]);
printf(" to e");
scanf("%d %d",&c[0],&d[0]);

}
for(i=0;i<5;i++)
{
p1[i].x=i+1;
p2[i].y=i+1;
p3[i].z=i+1;
}
for(i=0;i<5;i++)
{
if(c[i]==2)
{if(a[i]==1)
{
p2[d[i]].x=p1[b[i]].x;
p2[d[i]].y=p1[b[i]].y>p2[d[i]].y?p1[b[i]].y:p2[d[i]].y;
}
if(a[i]==3)
{p2[d[i]].z=p3[b[i]].z;
p2[d[i]].y=p3[b[i]].y>p2[d[i]].y?p3[b[i]].y:p2[d[i]].y;

}
}
if(c[i]==1)
{
if(a[i]==2)
{
p1[d[i]].y=p2[b[i]].y;
p1[d[i]].x=p2[b[i]].x>p1[d[i]].x?p2[b[i]].x:p1[d[i]].x;
}
if(a[i]==3)
{
p1[d[i]].z=p3[b[i]].z;
p1[d[i]].x=p3[b[i]].x>p1[d[i]].x?p3[b[i]].x:p1[d[i]].x;
}
}
if(c[i]==3)
{
if(a[i]==2)
{
p3[d[i]].y=p2[b[i]].y;
p3[d[i]].z=p2[b[i]].z>p3[d[i]].z?p2[b[i]].z:p3[d[i]].z;
}
if(a[i]==1)
{p3[d[i]].x=p1[b[i]].x;
p3[d[i]].z=p1[b[i]].z>p3[d[i]].z?p1[b[i]].z:p3[d[i]].z;
}
}
}

for(i=0;i<5;i++)
{
printf("%d ",p1[i].x);
printf("%d ",p1[i].y);
printf("%d ",p1[i].z);
printf("\n");
printf("%d ",p2[i].x);
printf("%d ",p2[i].y);
printf("%d ",p2[i].z);
printf("\n");
printf("%d ",p3[i].x);
printf("%d ",p3[i].y);
printf("%d ",p3[i].z);
printf("\n");
}


}

6 comments:

  1. Awesome Content written.
    The writer has shown a good style of writing in this article.
    Here is the best anti adware software for your computer?
    Do you know which is the best way to prevent and remove crysis ransomware.
    The latest news is that a Best pop up blocker.
    Checkout the most effective way to remove shortcut virus from your computer.

    ReplyDelete
  2. https://subpage.net/common-mining-safety-tips-for-mining-induction-worker/common-mining-safety-tips-for-mining-induction-worker/

    ReplyDelete
  3. https://flexcampic.com/how-to-start-a-proper-chainsaw-safety-and-operation/

    ReplyDelete
  4. https://www.darbaar.com/meaning-of-raksha-bandhan/

    ReplyDelete
  5. Learn the best programming languages, with DigitSutra coding courses, an online learning website. coding. Register now.

    ReplyDelete
  6. Give your glass windows a slick get done with Aluminium outlines.With the record breaking multi month of erection and appointing G Das enterprises is prepared to supply exceptionally quality aluminium expulsion item in Uganda and East African Market with the limit of 3500 ton for every annum.Aluminium for Windows in Uganda. We hope this might help you.

    ReplyDelete