# 删除线性表节点(线性表)

#include <iostream>
using namespace std;
struct node
{
int data;
node *next;
};
{
node *previous;              //前驱结点
node *current;               //当前结点
if(n<1)
{
return NULL;           //建立空链表
}
while(--n)
{
current=new node;            //建立新结点
cin>>current->data;          //输入数据
previous->next=current;      //新节点挂在表尾
previous=current;
}
previous->next=NULL;          //置表尾结束标志
}
{
node *temp;
/* 从头找到第一个不等于item的结点 */
{
delete temp; //删除该节点
}
return NULL;
while(current!=NULL)
{
/* 删除连续相同的结点*/
while(current!=NULL&&current->data==item)
{
/*
请在该部分填写缺少的代码
*/
}
previous->next=current; //重新连接结点
if(current==NULL)
break;
previous=current;
current=current->next;  //当前结点后移
}
}
{
while(current!=NULL)
{
cout<<current->data<<" ";    //输出结点数据
current=current->next;        //结点指针后移
}
}
int main()
{
int n,item;
cin>>n;
cin>>item;
return 0;
}

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

``1 2 3 4 5 6 7 9 10 ``

``````#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
int m,i,j,x,n;
scanf("%d",&m);
p=(int *)malloc(m*sizeof(int));
for(i=0;i<m;i++)
{
scanf("%d",&x);
p[i]=x;
}
scanf("%d",&n);
for(i=0;i<m;i++)
if(p[i]==n)
{
for(j=i;j<m-1;j++)
p[j]=p[j+1];
m--;
i--;
}
for(i=0;i<m;i++)
printf("%d ",p[i]);
return 0;
}
``````

``````#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
int m,i,j,x,n;
scanf("%d",&m);
p=(int *)malloc(m*sizeof(int));
for(i=0;i<m;i++)
{
scanf("%d",&x);
p[i]=x;
}
scanf("%d",&n);
for(i=0;i<m;i++)
if(p[i]==n)
{
for(j=i;j<m-1;j++)
p[j]=p[j+1];
m--;
i--;
}
for(i=0;i<m;i++)
printf("%d ",p[i]);
return 0;
}
``````