# Josephus Problem in C++

-josephus problem c++ -josephus problem code -josephus problem linked list  -Data structure and algorithm –Data structure and algorithm in C++ – Data structure using C++ -Data structure projects in C++ – Data structure Project idea -Data structure MCQ -Data structure Interview Question –data structure question paperfree course onlinepast papers -final year projects for computer science with source code -semester project ideas -computer programming -computer science interview questions- tutorial -cui

# C++ Code for Josephus Problem

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;

struct Josephus
{
char name;
struct Josephus *next;
};

typedef Josephus node;

void create(char *n)
{
New = new node;
strcpy(New -> name,n);
{
}

else
{
ptr -> next = New;
ptr = New;
}
}

node* remove(char *n)
{
while(strcmp(temp -> next -> name,n) != 0)
temp = temp -> next;

deleted = temp -> next;
temp -> next = temp -> next -> next;
return deleted;
}

int main()
{

int m,n,i,j;
char nme,sname;
do
{
cout << “enter total person = “;
cin >> m;
if(m <= 0)
cout << “\nPlease choose number greater than ” << m << endl;
}while(m <= 0);

do
{
cout << “\nEnter Number = “;
cin >> n;
if(n <= 0)
cout << “\nPlease enter the number greater than ” << m;
}while(n <= 0);

for(i = 0;i < m;i++)
{
cout << “\nEnter the Name = “;
cin >> nme;
create(nme);
}

cout << “\n\n your Starting name With : “;
cin >> sname;

while(strcmp(temp -> next -> name,sname) != 0)
{
temp = temp -> next;
if(strcmp(temp -> name,””) == 0)
{
cout << “\nSorry, there is no person in the list “;
getch();
return 0;
}
}

cout << endl << endl;
for(int k = 0;k < m;k++)
{
j = 0;
for(i = 1;i <= n;i++)
{
temp = temp -> next;
j++;
if(strcmp(temp -> name,””) == 0)
{
j–;
i–;
}

if(j == n)
{
nd = remove(temp -> name);
if(k != m-1)
cout << “Eliminated person : ” << nd -> name << endl;

else
cout << “\to take Hourse and Eleminate is ” << nd -> name << endl;

break;
}
}
}

getch();
return 0;
}

Josephus Problem