关于List
  • 板块学术版
  • 楼主MunYixty
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/7/2 14:41
  • 上次更新2023/11/3 11:53:43
查看原帖
关于List
868365
MunYixty楼主2023/7/2 14:41

求助List erase()如何调用 为什么我这个会报错啊

#include<bits/stdc++.h>  
using namespace std; 
 int read()
{
    int xr=0,F=1; char cr;
    while(cr=getchar(),cr<'0'||cr>'9') if(cr=='-') F=-1;
    while(cr>='0'&&cr<='9') 
        xr=(xr<<3)+(xr<<1)+(cr^48),cr=getchar();
    return xr*F;
} 
int n;

int main()
{
	list<int> L;    
  	n=read();
  	for(int i=1;i<=n;i++)
  	{
  		string op;
		cin>>op;
		if(op[0]=='R')
		{
			int x=read();
			L.push_back(x);
		}
		if(op[0]=='D')
		{
			int k;
			k=read();
			L.erase(k);
		}
		if(op[0]=='L')
		{
			int x;
			x=read();
			L.push_front(x); 		
		} 
		if(op[0]=='I')
		{
			if(op[1]=='L')
			{
				int k=read(),x=read();
				L.insert(k,x);
			} 
			else
			{
				int k=read(),x=read();
				L.insert(k+1,x);
			}
		}
		  		
	}
	for(auto i=L.front();i!=L.end();++i)
	{
		cout<<*i<<" ";
	}
    return 0;
}
2023/7/2 14:41
加载中...