6-5 链式表操作集 (20 分)

题目链接:https://pintia.cn/problem-sets/15/problems/728
这个题目是比较简单的,主要是考基本操作。我刚刚学做了很久才写出来,而且运行结果是对的,可提交是编译错误,但是我认为有参考价值。
在这里插入图片描述
在这里插入图片描述

List Insert( List L, ElementType X, Position P )
{
	Position tmp,t;
	tmp=L;
    t=NULL;
	if(P==L)
	{
		t=(List)malloc(sizeof(struct LNode));
		t->Data=X;
		t->Next=P;
		tmp=t;
		return tmp;
	}
	if(L==NULL)
	{
		printf("Wrong Position for Insertion\n");
		return ERROR;
	}
	while(L->Next!=P&&L->Next!=NULL)
	{
		L=L->Next;
	}
	if(L->Next==NULL&&P!=NULL)
			{
		printf("Wrong Position for Insertion\n");
		return ERROR;
	}
	else
	{
		t=(List)malloc(sizeof(LNode));
		t->Data=X;
		L->Next=t;
		t->Next=P;
		return tmp;
	}
}
Position Find( List L, ElementType X )
{
	while(L!=NULL&&L->Data!=X)
	{
		L=L->Next;
	}
	if(L==NULL)
	{
		return ERROR;
	}
	else
	{
		return L;
	}
}
List Delete( List L, Position P )
{
	Position tmp,t;
	tmp=L;
	t=NULL;
	if(L==P)
	{
		if(P==NULL)
		{
			return ERROR;
		}
		else
		{
			tmp=L->Next;
			free(L);
			return tmp;
		}
	}
	if(L==NULL)
	{
		printf("Wrong Position for Deletion\n");
		return ERROR;
	}
	while(L->Next!=P&&L->Next!=NULL)
	{
		L=L->Next;
	}
	if(L->Next==NULL)
	{
		printf("Wrong Position for Deletion\n");
		return ERROR;
	}
	else
	{
		L->Next=P->Next;
		free(P);
		return tmp;
	}
}
就是这样子了,水平不够,请多多包涵。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值