Breaking News
Loading...
Saturday, October 29, 2011

Bổ sung bài “Danh sách liên Kết”

10/29/2011 08:54:00 AM
          Hàm xóa một node sau node q:
void XoaNodeSauNodeQ(LIST &l, NODE *q)
{
if(q==NULL || q==l.Tail)
return;
NODE *p=q->pNext;
q->pNext=p->pNext;
if(q->pNext==l.Tail)
l.Tail = q;
delete p;
}
Hàm xóa node cui :

void XoaNodeTail(LIST &l)
{
NODE *p ;
if(l.Head==l.Tail)
{
delete l.Head;
l.Head = l.Tail = NULL;
return;
}
for(p=l.Head;p->pNext!=l.Tail;p=p->pNext);
p->pNext=NULL;
delete l.Tail;
l.Tail = p;
}


0 comments:

Post a Comment

 
Toggle Footer