.逆向打印单链表
void printlistback(Node* head)
{
if (NULL == head)
return;
printlistback(head->next);
printf("%d--->", head->data);
}
.删除一个无头单链表的非尾节点
void DeleteNotTailNode(Node* pos)
{
Node* Ppos = NULL;
assert(pos);
Ppos = pos->next;
pos->data = pos->next->data;
pos->next = pos->next->next;
free(Ppos);
Ppos = NULL;
}
.在无头单链表的一个非头节点前插入一个节点
void InsertNotHead(PNode pos,DataType data)
{
PNode PNewnode = NULL;
PNode _pos = pos; assert(pos);
PNewnode = Buynode(data);
PNewnode->next = _pos->next;
_pos->next = PNewnode;
_pos->data = _pos->next->data;
_pos->next = _pos->next->next;
free(PNewnode);
}
.单链表的逆置–前后指针
void Reverselist(Node** head)
{
assert(head);
Node* p = *head;
Node* nextnode = NULL;
Node* nownode = NULL;
if (p == NULL || p->next == NULL)
return;
while (p)
{
nownode = p;
p = p->next;
nownode->next = nextnode;
nextnode = nownode;
}
(*head)->next = NULL;
*head = nownode;
}
.单链表的逆置–头插法
void Reverselist(Node** head)
{
Node* p = NULL;
Node* q = NULL;
p=head->next;
head->next=NULL;
while(p)
{
q=p;
p=p->next;
q->next=head->next;
head->next=q;
}
}
.查找单链表的中间节点
Node* FindMidNode(Node* pHead)
{
Node* fast = head;
Node* slow = head;
while(fast&&fast->next)
{
fast = fast->next->next;
slow = slow->next;
}
return slow;
}