#include<iostream.h>

class cell {

int disc;

cell *next;

cell (int d)

{

disc = d;

next = this;

}

cell (int d, cell *n)

{

disc = d;

next = n;

}

friend class list;

};

class list{

cell *rear;

public:

int empty() { return rear == rear->next; }

void pop(int &i)

{

i = 0;

if( empty() ) return;

cell *front = rear->next;

rear->next = front->next;

i = front->disc;

delete front;

return;

}

void push(int d)

{

rear->next = new cell(d,rear->next);

}

list() { rear = new cell(0); }

~list()

{

int i,j,l;

long k;

while(!empty()) pop(i);

}

};

list pegs[3];

typedef int (*oper)(int);

int decr(int a)

{

a--;

if(a<0)

a=2;

return a;

}

int incr(int a)

{

a = (a+1)%3;

return a;

}

int main(void)

{

int n;

oper incr_decr;

int curr=0;

int p1 = 1, p2 = 2;

int d0,d1,d2;

cout << "Enter Number Of Discs:";

cin >> n;

for(int i = n; i > 0; i--)

pegs[0].push(i);

incr_decr = n%2 ? decr : incr; //conditional statement

while(1)

{

pegs[curr].pop(d0);

cout<<"Disc "<<d0<<" From "<<curr;

curr = incr_decr(curr);

pegs[curr].push(d0);

cout<<" To "<<curr<<endl;

p1 = incr_decr(p1);

p2 = incr_decr(p2);

if(!pegs[p1].empty() && !pegs[p2].empty())

{

pegs[p1].pop(d1);

pegs[p2].pop(d2);

if(d1 < d2)

{

pegs[p2].push(d2);

pegs[p2].push(d1);

cout<<"Disc "<<d1<<" From "<<p1<<" To "<<p2<<endl;

}

else

{

pegs[p1].push(d1);

pegs[p1].push(d2);

cout<<"Disc "<<d2<<" From "<<p2<<" To "<<p1<<endl;

}

}

else

{

if(pegs[p1].empty() && pegs[p2].empty())

break;

if(pegs[p1].empty())

{

pegs[p2].pop(d2);

pegs[p1].push(d2);

cout<<"Disc "<<d2<<" From "<<p2<<" To "<<p1<<endl;

}

else

{

pegs[p1].pop(d1);

pegs[p2].push(d1);

cout<<"Disc "<<d1<<" From "<<p1<<" To "<<p2<<endl;

}

}

}

return 1;

}

I have already compiled it and it works fine, but i need the source code to be in C.

Thanks for the help