THis is a death game all the peoples are atand in a circle and start from 1 1 kill the second 3 kill the 4 and so on
this is circular link list the rmaining person is one
for Example
1 2 3 4
are stand in a circle
1 3 are kill 2 and 4
and then 1 kill the 3
#include<iostream>
using namespace std;
int nums=0;
struct death
{
int num;
death *next;
}*head,*tail;
void addnumber(int num)
{
nums=num;
for(int i=1;i<=num;i++)
{
death *d= new death;
if(head==NULL)
{
d->num=i;
head =tail=d;
tail->next=head;
}
else
{
d->num=i;
tail->next=d;
tail=d;
tail->next=head;
}
}
}
void display()
{
death * temp;
temp =head;
while(temp->next!=head)
{
cout<<temp->num<<" ";
temp=temp->next;
}
cout<<temp->num<<" ";
cout<<endl;
}
void playGame()
{
death * temp,*temp1;
temp =head;
for(int i=0;i<nums;i++)
{
cout<<temp->num<<" ";
temp1= temp->next;
temp->next=temp1->next;
temp=temp->next;
temp1=NULL;
delete temp1;
} cout<<endl;
cout<<"So the remaining number is "<<temp->num<<" ";
}
int main()
{
head=tail=NULL;
int num;
while(1){
cout<<"Enter the number please "<<endl;
cin>>num;
switch(num)
{
case 1:
int num1;
cout<<"Enter the number of persons in this game"<<endl;
cin>>num1;
addnumber(num1);
break;
case 2:
display();
break;
case 3:
playGame();
break;
}}
}
https://getcryptotab.com/900383
No comments:
Post a Comment