Josephus Problem

  • Uploaded by: Partha Gayen
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Josephus Problem as PDF for free.

More details

  • Words: 167
  • Pages: 2
//Josephus problem #include<stdio.h> #include #include #include<string.h> #include<stdlib.h> typedef struct node { char name[10]; struct node *prev; }jp; jp* insert(jp *p) { jp *q; char c[10]; q=(jp*)malloc(sizeof(jp)); printf("\n Enter Name:"); scanf("%s",c); strcpy(q->name,c); if(p==NULL) { q->prev=q; p=q; return p; } q->prev=p->prev; p->prev=q; return p; } void show(jp *p) { jp *q; q=p; do { puts(q->name); printf("\n"); q=q->prev; }while(q!=p); } jp* search(jp *p,char s[10]) { int flag=0; jp *q; q=p; do { if(strcmp(q->name,s)==0) { flag=1; break; } q=q->prev; }while(q!=p); if(flag==1) return q; else printf("\n Name Not Found.\n");

return p; } void play(jp *p,int n) { int count; jp *q,*r; count=n; q=p; while(1) { for(count=n;count<9;count++) q=q->prev; r=q->prev; q->prev=r->prev; printf("\n Out: %s",r->name); getch(); if(q->prev==q) { printf("\n \n Winer is: %s",q->name); break; } q=q->prev; free(r); } } int main() { jp *p=NULL; char c[10]; int n,i; printf("\n How Many Boys?:"); scanf("%d",&n); for(i=0;i=10) { printf("\n Value is too large.\n"); exit(0); } play(p,n); return 1; }

Related Documents

Josephus Problem
June 2020 9
Problem
June 2020 31
Problem
June 2020 29
Problem
December 2019 39
Problem
December 2019 43
Problem
May 2020 21

More Documents from ""

Josephus Problem
June 2020 9
Fudcon3gbenson
June 2020 6
Chatt
June 2020 5
Client Frame
June 2020 8