展开全部
struct Node
{
int data ;
Node *next ;
};
typedef struct Node Node ;
//已知链表的头结点head,写一个函数把这个链表逆序 ( Intel)
Node * ReverseList(Node *head) //链表逆序
{
if ( head == NULL || head->next == NULL )
return head;
Node *p1 = head ;
Node *p2 = p1->next ;
Node *p3 = p2->next ;
p1->next = NULL ;
while ( p3 != NULL )
{
p2->next = p1 ;
p1 = p2 ;
p2 = p3 ;
p3 = p3->next ;
}
p2->next = p1 ;
head = p2 ;
return head ;
}
---------------------------------
循环链表的节点对换和删除。
//双向循环
list_node* earse(list_node* node)
{
if(node == rear) return node->next; //对于头节点可判断也可不判断。最好加上
list_node* next = node->next;
next->prev = node->prev;
node->prev->next = next;
delete node;
retrun next;
}
//单项循环
list_node* earse(list_node* node)
{
// if(node == rear) return node->next; //对于头节点可判断也可不判断。最好加上
list_node* p = rear;
while(p->next != node) p=p->next;
p->next = node->next;
delete node;
retrun p->next;
}
{
int data ;
Node *next ;
};
typedef struct Node Node ;
//已知链表的头结点head,写一个函数把这个链表逆序 ( Intel)
Node * ReverseList(Node *head) //链表逆序
{
if ( head == NULL || head->next == NULL )
return head;
Node *p1 = head ;
Node *p2 = p1->next ;
Node *p3 = p2->next ;
p1->next = NULL ;
while ( p3 != NULL )
{
p2->next = p1 ;
p1 = p2 ;
p2 = p3 ;
p3 = p3->next ;
}
p2->next = p1 ;
head = p2 ;
return head ;
}
---------------------------------
循环链表的节点对换和删除。
//双向循环
list_node* earse(list_node* node)
{
if(node == rear) return node->next; //对于头节点可判断也可不判断。最好加上
list_node* next = node->next;
next->prev = node->prev;
node->prev->next = next;
delete node;
retrun next;
}
//单项循环
list_node* earse(list_node* node)
{
// if(node == rear) return node->next; //对于头节点可判断也可不判断。最好加上
list_node* p = rear;
while(p->next != node) p=p->next;
p->next = node->next;
delete node;
retrun p->next;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询