完全不会的蒟蒻
查看原帖
完全不会的蒟蒻
1432277
limoxuan0712楼主2025/1/14 20:25
#include<iostream>
using namespace std;
struct node{
	int date;
	node* Next;
};
void Print_list(node* T){
	if(T==NULL) return ;
	while(T != NULL){
		cout<<T->date<<" ";
		T=T->Next;
	}
	cout<<endl;
}
void Tail_list(node* &T, int val){
	if(T==NULL){
		node* p = new node;
		p->date = val;
		p->Next = NULL;
		T = p;
		return;
	}
	node* cur = T;
	while(cur->Next != NULL)
		cur = cur->Next;
	node* p = new node;
	p->date = val;
	p->Next = NULL;

	cur->Next = p;
}
void del_nxt_list(node* &T,int val){
	if(T==NULL) return ;
	node* cur = T;
	while(cur->Next!=NULL){
		if(cur->date == val){
			cur->Next=cur->Next->Next;
			return ;
		}
		else{
			cur=cur->Next;
		}
	}
}
void behind_list(node* &T,int x,int y){
	if(T==NULL)return ;
	node* cur=T;
	node* ans = new node;
	ans->date=y;
	ans->Next=NULL; 
	while(cur->date!=x){
		if(cur->date==x){
			cur->Next=ans;
			ans->Next=cur->Next->Next;
			return ;
		}
		else{
			cur=cur->Next;
		}
	}
}
void behind_answer_list(node* T,int x){
	if(T==NULL)return ;
	node* cur=T;
	node* ans = new node;
	ans->date=x;
	ans->Next=NULL;
	while(cur->date!=x){
		if(cur->date==x){
			cout<<ans->Next->date<<endl;
			return ; 
		}
		else{
			cur=cur->Next;
		}
	}
}
int main(){
	int n,cz,a,b;
	cin>>n;
	node* T = NULL;
	Tail_list(T,1);
	for(int i=1;i<=n;i++){
		cin>>cz;
		if(cz==1){
			cin>>a>>b;
			behind_list(T,a,b);
		}else if(cz==2){
			cin>>a;
			behind_answer_list(T,a);
		}else{
			cin>>a;
			del_nxt_list(T,a);
		}
	}
	delete T;
	return 0;
}
/*
6
35 12 99 26 8 66
*/
2025/1/14 20:25
加载中...