# 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[20];
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[15],sname[15];
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

Single link listÂ Â  Â  Â  Â  Â  Â  Â  Â  StackÂ  Â Â  Â  Â  Â  Â  Â AVL TreesÂ  Â  Â  Â  Â  Â  Â Binary searchÂ Â  Â  Â  Â  Â Counting Sort

Doubly link listÂ  Â  Â  Â  Â  Â  Â  Â QueueÂ Â  Â  Â  Â  Â  Â  Â GraphsÂ  Â  Â  Â  Â  Â  Â  Â  Â  Bubble SortÂ  Â  Â  Â  Â  Â  Â  Â Radix sort

Circular link listÂ Â  Â  Â  Â  Â  Â  Â Binary search treeÂ Â  Â  Â  HashingÂ Â  Â  Â  Â  Insertion SortÂ Â  Â  Â  Â  Bucket Sort

Josephus ProblemÂ Â  Â  Â  Â  Â Tree TraversalÂ Â  Â  Â  Â  Â  Â  Â HeapsÂ Â  Â  Â  Â  Â  Â  Â  Â Quick SortÂ  Â  Â  Â  Â  Â  Â  Merge Sort

Â

## At Cui tutorial, courses, past papers and final year projects

#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 paper #free course online #past papers #final year projects for computer science with source code #semester project ideas #computer programming #computer science interview questions# tutorial #cuiÂ

#courses #pastpaper #Finalarproject #tutorial #cui #project #programming #computer science

Scroll to Top