2/22作业

1.按位置插入

void insert_pos(seq_p L,datetype value,int pos)
{
    if(L==NULL)
    {
        printf("入参为空\n");
        return;
    }
    if(seq_full(L))
    {
        printf("表已满\n");
        return;
    }
    if(pos>L->len||pos<0)
    {
        printf("无法插入\n");
        return;
    }


    for(int i=L->len-1;i>=pos;i--)
    {
        L->date[i+1]=L->date[i];

    }
    L->date[pos]=value;
    L->len++;
}


2.

void del_pos(seq_p L,int pos)
{
    if(L==NULL)
    {
        printf("入参为空\n");
        return;
    }
    if(seq_empty(L))
    {
        printf("表为空\n");
        return;
    }

    for(int i=pos;i<L->len-1;i++)
    {
        L->date[i]=L->date[i+1];
    }
    L->len--;

}

3.

void del(seq_p L)
{    
    if(L==NULL)
    {
        printf("入参为空\n");
        return;
    }
    if(seq_empty(L))
    {
        printf("表为空\n");
        return;
    }
    for(int i=0;i<L->len;i++)
    {
        for(int j=i+1;j<L->len;j++)
        {
            if(L->date[i]==L->date[j])
            {
                del_pos(L,j);
                j--;
                return;                
            }
        }

    }
}

4.

#include "link_list.h"
link_p creat_head()
{
    link_p L = (link_p)malloc(sizeof(link_list));
    if(L==NULL)
    {
        printf("空间申请失败\n");
    }
    L->len=0;
    L->next=NULL;
    return L;
}

link_p creat_node(datatype data)
{
    link_p new = (link_p)malloc(sizeof(link_list));
    if(new==NULL)
    {
        printf("空间申请失败\n");
    }
    new->data = data;
    return new;
}

void insert_head(link_p H,datatype data) 
{
    if(H==NULL)
    {
        printf("入参为空\n");
        return;
    }
    link_p new = creat_node(data);
    new->next = H->next;
    H->next = new;
    H->len++;
}

void insert_tail(link_p H,datatype data)
{
    if(H==NULL)
    {
        printf("入参为空\n");
        return;
    }
    link_p new = creat_node(data);
    link_p temp=H;
    while(temp->next !=NULL)
    {
        temp=temp->next;
    }
    temp->next=new;
    H->len++;

}
void out_put(link_p H)
{

    if(H==NULL)
    {
        printf("入参为空\n");
        return;
    }
    while(H != NULL)
    {
        if(H->next != NULL)
        {
            printf("%d\n",H->data);
        }
        else
        {
            printf("%d\n",H->data);
        }
        H=H->next;
    }
}
 

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值