Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Make the first file named ex.h</p> <pre><code>#include&lt;iostream.h&gt; template &lt;class T&gt; class ex { private: struct node { T data; struct node *next; }; struct node *head,*front,*rear; public: ex() { head=new node; head-&gt;next=NULL; front=rear=head; } void enqueue(T x); T dequeue(); void print(); void move_next(); }; </code></pre> <p>Second file into ex.cpp</p> <pre><code>#include "ex.h" template &lt;class T&gt; void ex&lt;T&gt;::enqueue(T x) { node *p; p=new node; p-&gt;data=x; if(head-&gt;next==NULL) { front=rear=p; head-&gt;next=p; p-&gt;next=p; } else { rear-&gt;next=p; p-&gt;next=front; rear=rear-&gt;next; } } template&lt;class T&gt; T ex&lt;T&gt;::dequeue() { node *t; T x; t=front; x=t-&gt;data; front=front-&gt;next; rear-&gt;next=front; delete(t); return x; } template&lt;class T&gt; void ex&lt;T&gt;::print() { node *p=front; do { cout&lt;&lt;p-&gt;data&lt;&lt;endl; p=p-&gt;next; }while(p!=rear-&gt;next); } template&lt;class T&gt; void ex&lt;T&gt;::move_next() { front=front-&gt;next; rear=rear-&gt;next; } </code></pre> <p>And the third file into Main.cpp or something.</p> <pre><code>#include "ex.cpp" void main() { ex&lt;int&gt; e; int m,n,i,d; cout&lt;&lt;"Enter the number of people"; cin&gt;&gt;n; cout&lt;&lt;"Enter the number of passes"; cin&gt;&gt;m; for(i=1;i&lt;=n;i++) e.enqueue(i); cout&lt;&lt;"The players are "; e.print(); cout&lt;&lt;"Eliminated in order "; while(n&gt;1) { for(i=1;i&lt;=m;i++) e.move_next(); d=e.dequeue(); cout&lt;&lt;d&lt;&lt;endl; n--; } d=e.dequeue(); cout&lt;&lt;"Winning player: "&lt;&lt;d&lt;&lt;endl; } </code></pre> <p>Then compile it. Also, it's supposed to be <code>int main()</code> not <code>void main()</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload