18. C畉utr炭cd畛li畛u1v叩thu畉tgi畉iC畉UTRCD畛LI畛UVGI畉ITHU畉T1 Click To Edit Master Title Style
18
Hu畛 1 N炭t 畛ng Tr動畛c N炭t Q
void DeleteBeforeQ(DList &l,DNode *q)
{
DNode *p;
if(q!=NULL) //tuc ton tai node q
{
p=q->pPre;
if(p!=NULL)
{
q->pPre=p->pPre;
if(p==l.pHead)//p la Node dau cua danh sach
l.pHead=q;
else //p khong phai la node dau
p->pPre->pNext=q;
delete p;
}
}
else
DeleteEnd(l);
}
19. C畉utr炭cd畛li畛u1v叩thu畉tgi畉iC畉UTRCD畛LI畛UVGI畉ITHU畉T1 Click To Edit Master Title Style
19
Xo叩 1 Ph畉n T畛 C坦 Kho叩 = X
int DeleteX(DList &l,int x)
{
DNode *p;
DNode *q;
q=NULL;
p=l.pHead;
while(p!=NULL)
{
if(p->Info==x)
break;
q=p;//q la Node co truong Info = x
p=p->pNext;
}
if(q==NULL) return 0;//khong tim thay Node nao co truong Info =x
if(q!=NULL)
DeleteLastQ(l,q);
else
DeleteFirst(l);
return 1;