Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 37 additions & 38 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/*
* This is a doubly circular link-list!
*/

#include<stdio.h>
#include<malloc.h>

Expand All @@ -29,12 +28,11 @@ int main(int argc, char** argv)
*/

struct node *root,*n,*temp,*k,*p;
float i=0, j=0, Starting_Value=0, Last_Value=0, Choosen_Value=0, Per_Value=0;
int My_Choice=0,Clock_Choice=0, flag=0;
float i=0,j=0,a=0,b=0,c=0,value=0;
int count=0,flag=0,ch=0;

root=NULL; //Initializing root with NULL


printf("\n**********//// THE MAGIC BEGAINS NOW! ;) ////**********\n");
printf("\nSuppose these is a monster who kills every nth person standing in a circle\n");
printf("Suppose you can start a circle of people with any integer number you want!\n");
Expand All @@ -46,15 +44,15 @@ int main(int argc, char** argv)
*/

printf("So give the staring number\n");
scanf("%f",&Starting_Value);
scanf("%f",&a);

/*
* Now give the end point of the Circle!
*/


printf("Now give me the last number of the circle ;)\n");
scanf("%f",&Last_Value);
scanf("%f",&b);

/*
* Now in this loop node type variable containing information part and
Expand All @@ -63,7 +61,7 @@ int main(int argc, char** argv)
* of inputs!
*/

for(i=Starting_Value; i<=Last_Value; i++)
for(i=a;i<=b;i++)
{
n=(struct node *)malloc(sizeof(struct node));
n->info=i;
Expand All @@ -83,94 +81,95 @@ int main(int argc, char** argv)

root->link2=n;
n->link=root;

/*
* With these statements I have made link-list circular!
* So now starting node have the address of the last node!
*/


printf("Please enter the value of the nth person\n");
scanf("%f",&Per_Value);

scanf("%f",&value);
/*
* This will be the value of n (the person number to be killed)
*/

printf("\n");

printf("How you want monster to kill person Clockwise (1) or");
printf(" Anti-clockwise (2)\n <1/2>\n");
scanf("%d",&Clock_Choice);

printf("How you want monster to kill person..?\n");
printf("Press: \n")
printf("1. Clockwise \n");
printf("2. Anti-clockwise \n");
printf("Enter your choice:\n");
scanf("%d",&ch);
/*
* This will be the value which decide the loop will run Clockwise
* or Anti-Clockwise
*/

printf("Very good! ;) Keep it You played very well\n");
printf("Very good! Keep it up. You played very well\n");
printf("The game is not yet over !!\n");
printf("Now I will play a game with you\n");
printf("Choose a position for you before getting the result\n");
printf("Lets see I will kill you or you will be the safe person\n");
printf("Choose a position for you in the circle \n");
printf("Lets see I wll kill you or you will be the safe person\n");

scanf("%d",&My_Choice);
Per_Value = Per_Value-1;
Choosen_Value = Last_Value-Starting_Value+1;
scanf("%d",&count);
value=value-1;
c=b-a+1;


if(Clock_Choice==2)
if(ch==2)
{
while(Choosen_Value > Per_Value)
while(c>value)
{
for(i=0; i<Per_Value; i++)
for(i=0;i<value;i++)
{
if(i == Per_Value-1)
if(i==value-1)
p=root;
root = root->link2;
root=root->link2;
}
p->link2 = root->link2;
root = p->link2;
Choosen_Value--;
p->link2=root->link2;
root=p->link2;
c--;
}

k = root;
if(My_Choice == root->info)
k=root;
if(count==root->info)
flag=1;
printf("The value is %0.f\n",root->info);
root = root->link2;
root=root->link2;
while(root!=k)
{
printf("The value is %0.f\n",root->info);
if(My_Choice==root->info)
if(count==root->info)
flag=1;
root=root->link2;
}
}

else
{
while(Choosen_Value > Per_Value)
while(c>value)
{
for(i=0; i<Per_Value; i++)
for(i=0;i<value;i++)
{
if(i==Per_Value-1)
if(i==value-1)
p=root;
root=root->link;
}
p->link=root->link;
root=p->link;
Choosen_Value--;
c--;
}

k=root;
if(My_Choice==root->info)
if(count==root->info)
flag=1;
printf("The value is %0.f\n",root->info);
root=root->link;
while(root!=k)
{
printf("The value is %0.f\n",root->info);
if(My_Choice==root->info)
if(count==root->info)
flag=1;
root=root->link;
}
Expand Down