zoukankan      html  css  js  c++  java
  • 在O(1) 时间删除链表节点

    struct Node {
    	int val;
    	Node * next;
    };
    void deleteNode(Node ** head, Node * target)
    {
    	assert(head != NULL && *head != NULL && target != NULL);
    	
    	//头结点的判断
    	if(*head == target)
    	{
    		*head = target->next;
    		delete target;
    	}
    	
    	//尾节点的判断
    	if(target->next == NULL){
    	
    		Node *p = *head;
    		while(*p ->next != head)
    			p = p->next;
    	
    		p->next = NULL;
    		delete target ;
    	}else{
    	
    		Node *p = target-next;
    		target->val = p->val;
    		target->next = p->next;
    		delete p;
    	}
    }
    

      



  • 相关阅读:
    字符串,列表,集合,字典,元组方法
    内置对象方法
    学生管理系统(2)
    1207
    PSP总结
    1130
    1123
    1118
    1109
    评论
  • 原文地址:https://www.cnblogs.com/graph/p/3320910.html
Copyright © 2011-2022 走看看