123 Eng

### Engineering the engineers™

Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

Computer Science / IT
Electronics
Electrical
Mechanical
Chemical
Civil

CAT / MBA

GMAT / Foreign MBA
Latest Jobs

Displaying  Source Code(s)

 josephus problem -------------------------------------------------------------------------------- Description : To solve josephus problem using circular queue and templates Code : //////////////////Header file #include template class ex { private: struct node { T data; struct node *next; }; struct node *head,*front,*rear; public: ex() { head=new node; head->next=NULL; front=rear=head; } void enqueue(T x); T dequeue(); void print(); void move_next(); }; //////////////////Implementation file #include "ex.h" template void ex::enqueue(T x) { node *p; p=new node; p->data=x; if(head->next==NULL) { front=rear=p; head->next=p; p->next=p; } else { rear->next=p; p->next=front; rear=rear->next; } } template T ex::dequeue() { node *t; T x; t=front; x=t->data; front=front->next; rear->next=front; delete(t); return x; } template void ex::print() { node *p=front; do { cout<data<next; }while(p!=rear->next); } template void ex::move_next() { front=front->next; rear=rear->next; } /////////////////Application file #include "ex.cpp" void main() { ex e; int m,n,i,d; cout<<"Enter the number of people
; cin>>n; cout<<"Enter the number of passes
; cin>>m; for(i=1;i<=n;i++) e.enqueue(i); cout<<"The players are
; e.print(); cout<<"Eliminated in order
; while(n>1) { for(i=1;i<=m;i++) e.move_next(); d=e.dequeue(); cout<

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG