数据结构练习(24)在O(1)时间删除链表结点
http://zhedahht.blog.163.com/blog/static/254111742007112255248202/
struct Listnode { int m_Key; Listnode *m_Next; }; void DeleteNode(Listnode *head, Listnode *deletenode) { if (!head || !deletenode) return ; if (deletenode->m_pNext) { Listnode *p = deletenode->m_Next; deletenode->m_Key = p->m_Key; deletenode->m_Next = p->m_Next; delete p; p = nullptr; } else { Listnode *p = head; while (p->m_Next != deletenode) p = p->m_Next; p->m_Next = nullptr; delete deletenode; deletenode = nullptr; } }
-------------------------------------------------------
kedebug
Department of Computer Science and Engineering,
Shanghai Jiao Tong University
E-mail: kedebug0@gmail.com
GitHub: http://github.com/kedebug
-------------------------------------------------------