# 链表基本操作---指定结点删除

#include <stdio.h>
#include <stdlib.h>
typedef struct NODE
{
int data;           //数据域
struct NODE *next;  //指针域，指向下一个结点
} Node;
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int i;
p1 = (Node *)malloc(sizeof(Node));
p1->data = a[0];
for( i = 1 ; i < 10 ; i++)  //对链表进行赋值，创建包含1-10的链表
{
p2 = (Node *)malloc(sizeof(Node));
p1->next = p2;
p2->data = a[i];
p2->next = NULL;
p1 = p2;
}
p2 = p1->next;
printf("%d",p1->data);
while( p2 != NULL )
{
if( p2->data == 3 || p2->data == 6)     //对于数据域是3或者是6的结点进行删除
{
p1->next = p2->next;
free(p2);
/*******在下面填写代码***********/

/*******在上面填写代码***********/
}
printf(" %d",p2->data);
p1 = p2;
p2 = p2->next;
}
return 0;
}

``1 2 4 5 7 8 9 10``

``````
#include <stdio.h>
#include <stdlib.h>
typedef struct NODE
{
int data;           //数据域
struct NODE *next;  //指针域，指向下一个结点
} Node;
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int i;
p1 = (Node *)malloc(sizeof(Node));
p1->data = a[0];
for( i = 1 ; i < 10 ; i++)  //对链表进行赋值，创建包含1-10的链表
{
p2 = (Node *)malloc(sizeof(Node));
p1->next = p2;
p2->data = a[i];
p2->next = NULL;
p1 = p2;
}
p2 = p1->next;
printf("%d",p1->data);
while( p2 != NULL )
{
if( p2->data == 3 || p2->data == 6)     //对于数据域是3或者是6的结点进行删除
{
p1->next = p2->next;
free(p2);
p2 = p1->next;

}
printf(" %d",p2->data);
p1 = p2;
p2 = p2->next;
}
return 0;
}
``````

``````
#include <stdio.h>
#include <stdlib.h>
typedef struct NODE
{
int data;           //数据域
struct NODE *next;  //指针域，指向下一个结点
} Node;
int main()
{
int a[] = {1,2,3,4,5,6,7,8,9,10};
int i;
p1 = (Node *)malloc(sizeof(Node));
p1->data = a[0];
for( i = 1 ; i < 10 ; i++)  //对链表进行赋值，创建包含1-10的链表
{
p2 = (Node *)malloc(sizeof(Node));
p1->next = p2;
p2->data = a[i];
p2->next = NULL;
p1 = p2;
}
p2 = p1->next;
printf("%d",p1->data);
while( p2 != NULL )
{
if( p2->data == 3 || p2->data == 6)     //对于数据域是3或者是6的结点进行删除
{
p1->next = p2->next;
free(p2);
p2 = p1->next;

}
printf(" %d",p2->data);
p1 = p2;
p2 = p2->next;
}
return 0;
}
``````