Code:
class node { private: int number; node *next; public: node(int num=0,node *p=NULL) { number=num; next=p; } friend class stack; }; class stack { private: node *top; public: stack(){ node *top=NULL;}; ~stack(){ node *top=NULL;}; void push(stack &s,int d) { node *p=new node(d); if(s.top==NULL) s.top=p; else { p->next=s.top; top=p; } } void print(stack s) { node *p; p=new node; p=s.top; while(p!=NULL) { [B][COLOR=#FF0000]cout<<p->number;[/COLOR][/B] p=p->next; } } }; int main() { int x,temp; stack s; node *p; cout<<"\nNhap vao 1 so:"; cin>>x; while(x!=0) { s.push(s,x%2); x/=2; } cout<<"\n So nhi phan:"; s.print(s); getch(); return 0; }
Comment