#include
#include
#include
#include
using namespace std;
typedef struct DL
{
int arg;
struct DL *next;
}stack;
stack *push(stack*,int);
void doi(stack *,int);
int pop(stack*);
stack *start=NULL;
/******************main********************************/
int main()
{
int m;
printf("\n Nhap so can doi: ");
-
doi(start,m);
printf("\n Day nhi phan thu duoc:\n");
while(start!=NULL)
{
cout<<pop(start)<<" ";
start=start->next;
}
getch();
-
}
/***************khoi tao danh sach ngan xep*************************/
stack *push(stack *p,int n)
{
if(p==NULL)
{
p
=(stack
*)malloc(sizeof(stack
));
p->arg=n;
p->next=NULL;
}
else
{
stack *temp;
temp
=(stack
*)malloc(sizeof(stack
));
temp->arg=n;
temp->next=p;
p=temp;
}
return (p);
}
/*******************doi tu co so 10 sang co so 2*************************/
void doi(stack *p,int n)
{
stack *temp;
temp=p;
while(n/2!=0)
{
temp=push(temp,n%2);
n=n/2;
}
temp=push(temp,n%2);
}
/*****************in ra tung phan tu trong danh sach********************/
int pop(stack *p)
{
stack *temp1,*q;
int a;
temp1=p;
a=temp1->arg;
q=temp1;
return a;
-
}
0 nhận xét:
Đăng nhận xét