---
title: "How to delete a node in a LinkList ?"
author: "standalone"
date: "2010-07-06T21:22:52Z"
tags: []
categories: ["编程语言"]
slug: "how-to-delete-a-node-in-a-linklist"
draft: false
lastmod: "2012-10-29T10:34:15Z"
id: 706934
url: "https://standalone.iteye.com/blog/706934"
---

If only given the pointer to the node to be deleted? Note the node is not the first one nor the last.

 

如果在单链表中删除一个指定的结点？ 需要注意的是不是头尾结点。

 

这到题其实就是个小技巧，没有告诉前面的一个结点怎么做删除呢？答案就是把后面结点的内容拷贝过来！这个问题的前提是结点不能使首尾结点，否则就没法做了。

 

假设数据内容是整型，简化问题。

 

```
void delete(Node p){
   Node q = p.next;
   p.data = q.data;
   p.next = q.next;
}
```