假设某个单向循环链表的长度大于 1. 且表中没有头结点也没头指针,已知 m 为面向链表中某个结点的指针。试编写算法在链表中删除 m 所在结点的后继结点。
// 假设链表定义如下 struct Link{ Link* next; int val; }; void fun(Link* m) { Link* p = m->next; m->next = p->next; delete p; }
public static class Node{ int value; Node next; public Node(int n){ this.value = n; this.next = null; } } public static delete Node(Node m){ Node p = m.next; m.next = p.next; delete p; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题