CTDL GT
CTDL GT
DON VONG:
typedef struct node THEM DAU:
{ void InsertFirst(NodePtr &pList, int
DataType info; x)
node* next; {NodePtr node;
} NODE; node = new NODE;
typedef NODE* NodePtr; node->info = x;
NodePtr pList; if (pList == NULL)
KIEM TRA : { pList = node;
int IsEmpty(NodePtr &pList) pList->next = pList;
{ }
return (pHead == NULL); else
} { node->next = pList->next;
SHOW LIST: pList->next = node;
void ShowList(NodePtr }
&pList) }
{ NodePtr p; //p con tro de THEM CUOI:
duyet voidInsertFirst(NodePtr &pList, int x)
if (pList == NULL ) NodePtr node;
return; node = new NODE;
p = pList->next; node->info = x;
do if (pList == NULL)
{ ShowNode(p); { pList = node;
p = p->next; pList->next = pList;
} while (p != pList->next);} }
XOA DAU: else
void DeleteFirst(NodePtr &pList) { node->next = pList->next;
{ NodePtr p; pList->next = node;
if (pList == NULL) pList=node;
return; }
else if (pList == pList->next) }
{ delete pList; THEM SAU P:
pList = NULL; void InsertAfter(NodePtr &p, int x)
} { NodePtr node;
else node = new NODE;
{ p = pList->next; node->info = x;
pList->next = p->next; if (p == NULL)
delete p; return;
}} else
XOA CUOI: { node->next = p->next;
void DeleteLast (NodePtr &pList) p->next = node;
{ NodePtr p; }
if (pList == NULL) }
return; THEM TRUOC P:
else void InsertBefore(NodePtr &p, int x)
if (pList == pList->next) { NodePtr node;
{ delete pList; node = new NODE q;
pList = NULL; node->info = x;
} if (p == NULL)
else return;
{ p = pList; else
NodePtr q = pList -> next; { q->next=p;
while ( q -> next != pList) q->next=node->next;
q = q -> next; node->next = p;}}
q -> next = pList -> next; TIM KIEM:
pList = q; NodePtr Search (NodePtr &pList, int
delete p; x)
} {
} NodePtr p; //p con trỏ tìm kiếm
if (pList ==NULL)
return NULL;
p = pList->next;
do {
p = p->next;
}
while (p->info!=x &&p!=pList>next);
if ( p->info == x) return p;
return NULL;
}