无头单链表第k个结点的删除

xiaoxiao2021-02-27  464

#include <iostream> using namespace std; struct Node { Node*_next; Node * _pre; size_t data; }; void pop_no_headlistthe_k_node( Node* pHead, size_t k) { Node* cur1 = pHead; Node* cur2 = pHead; for (size_t idx = 0; idx < k - 1; idx++) { cur1 = cur1->_next; } while (cur1) { cur1 = cur1->_next; cur2 = cur2->_next; } cur2->_pre->_next = cur2->_next; cur2->_next->_pre = cur2->_pre; delete cur2; cur2 = NULL; }
转载请注明原文地址: https://www.6miu.com/read-2094.html

最新回复(0)