链表学习(偷)

b = b * 10 + (a % 10)

#include<bits/stdc++.h>
using namespace std;
typedef struct student{
int num;
int score;
struct student *next;
}stu;
void add(stu **head,stu *p)
{
stu *mov=*head;
if(*head==NULL)
{
*head=p;
p->next=NULL;
}
else
{
while(mov->next!=NULL)
{
mov=mov->next;
}
mov->next=p;
p->next=NULL;
}
}
void fre(stu **head)
{
stu *qb=*head;
while(*head!=NULL)
{
*head=(*head->next);
free(qb)
qb=NULL;
}
}
int main()
{
stu *head,*p;
scanf("%d",&n);
for(int i=1;i<n;i++)
{
p=(stu*)malloc(sizeof(stu));
scanf("%d%d",&p->num,&p->score);
add(&head,p);
}



}
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef struct student{
	int x;
	struct student *next;
}stu;
int y,n,j,k,l;
void add(stu **head,int x1,stu* p) 
{
	stu *mov=*head;
	
	while(mov->x!=x1&&mov->next!=0)
	{
		mov=mov->next;
		
		if(mov->next==0)
		{
			mov->next=p;
			p->next=0;
			
			return;
		}
	}
	p->next=mov->next;
	mov->next=p;
	
	
}
void seach(stu**head,int y)
{
	stu *mov=*head;
	while(mov->next!=0&&mov->x!=y)
	{
		mov=mov->next;
	}if(mov->next==0)
	{
		cout<<'0'<<endl;
		return;
	}
	
	if(mov->x==y)
	{
		mov=mov->next;
		cout<<mov->x<<endl;
		return;
	}
	
}
void delet(stu **head,int y)
{
	stu *mov=*head,*i;
	while(mov->x!=y&&mov->next!=0){
		mov=mov->next;
	}
	if(mov->next==0)
		return;
	
	i=mov->next;
	mov->next=i->next;
	
	free(i);
	i=0;
	
}

int main()
{
	stu q,*head,*m[N],*p;
	q.x=1;
	head=&q;
	q.next=0;
	m[0]=head;
	int o=1;
	cin>>n;
	for(int i=0;i<n;i++){
		
		cin>>j;
		if(j==1){
			cin>>k>>l;
			p=(stu*)malloc(sizeof(stu));
			p->x=l;
			p->next=0;
			m[o++]=p;
			add(&head,k,p);
			
		}
		if(j==2)
		{
			cin>>k;
			seach(&head,k);
		}
		if(j==3){
			cin>>k;
			delet(&head,k);
		}
		
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值