链表练习— 删除结点

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Fiverya/article/details/88814159

对给定的单链表 L ,设计一个算法,删除 L 中值为 x 的结点的直接前驱结点。

#include<iostream>  
#include<list>  
using namespace std;  
int main()  
{  
    list<int> LA,LB;  
    list<int>::iterator j,n;  
    int x,y;
	do 
    {   cin>>x;
        LA.push_back(x);  
    } while(getchar()!='\n');
      

for (j = LA.begin();j!= LA.end();j++)   
    if(*j==y)
	{ LA.erase(--j); break;}
    n=LA.begin();
    cout<<*n;n++;
for (;n!= LA.end();n++)
	{ 
     cout<<" "<<*n;
	}
    cout<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Fiverya/article/details/88814159