#include "stdio.h"
#include "conio.h"
struct node
{
int info;
node *next;
};
struct list
{
node *dau;
};
void list_null(list &l)
{
l.dau=NULL;
}
node* tao(int a)
{
node *p=new node;
if(p==NULL)return NULL;
p->info=a;
p->next=NULL;
return p;
}
void add_dau(list &l,node *p)
{
if(l.dau==NULL)
l.dau=p;
else
{
p->next=l.dau;
l.dau=p;
}
}
void muoi_hai(list &l,int a)
{
while(a>0)
{
node *p=tao(a%2);
add_dau(l,p);
a=a/2;
}
}
void lay_xoa_het(list &l)
{
while(l.dau!=NULL)
{
node *p=l.dau;
printf("%d",l.dau->info);
l.dau=l.dau->next;
delete p;
}
}
void pop(list &l,int &a)
{
node *p=l.dau;
l.dau=l.dau->next;
a=p->info;
delete p;
}
void main()
{
list l;
list_null(l);
int a;
printf("nhap so muon doi 10 > 2 ");
scanf("%d",&a);
muoi_hai(l,a);
lay_xoa(l);
getch();
}
hàm pop như mình hiểu là lấy và xóa nhưng chỉ lấy đc 1 thông tin ra ngoài nhưng ở bài toán đổi cơ số thì chúng ta cần nguyên 1 list vậy khi nào hàm pop hữu dụng ? đối với bài toán nào thì cần đến hàm pop ?