单链表类

这个tmd我傻了老是给我RE老脸都丢没了

#include<bits/stdc++.h>
using namespace std;
int  a[30000000];
struct Boe
{
    int x;
    Boe *next;
};
struct danlink
{
    Boe *first;
    danlink(){
        first=new Boe;
        first->next=NULL;
    }
    danlink(int *a,int n){
        first=new Boe;
        first->next=NULL;
        Boe *last=first;
        for(int i=1;i<=n;i++){
            Boe *y=new Boe;
            y->x=a[i];
            last->next=y;
            last=y;
        }
        last->next=NULL;
    }
    danlink(int *a,int n,int o){
        first=new Boe;
        first->next=NULL;
        for(int i=1;i<=n;i++){
            Boe *x=new Boe;
            x->x=a[i];
            x->next=first->next;
            first->next=x;
        }
    }
    ~danlink(){
        for(Boe *i=first->next;i;)
        {
            Boe *x=i;
            i=i->next;
            delete x;
        }
        delete first;
    }
    void print()
    {
        for(Boe *i=first->next;i;i=i->next)
            cout<<i->x<<' ';
        cout<<endl;
        return;
    }
    bool place(int w){
        int flag=0;
        Boe *x=first;//就这我给弄成first->next了然后突然明白试了试删除第一个位置的还真不行了。啊啊啊谨记谨记
        for(Boe *i=first->next;i;x=i,i=i->next)
        {
            flag++;
            if(flag==w)
            {
                x->next=i->next;
                delete i;
                return 1;
            }
        }
        return 0;
    }
    bool valuee(int v){
        Boe *x=first;
        for(Boe *i=first->next;i;x=i,i=i->next)
        {
            if(i->x==v)
            {
                x->next=i->next;
                delete i;
                return 1;
            }
        }
        return 0;
    }
};
int main()
{
    int i=0,n;
    while(cin>>n,n)
    {
        a[++i]=n;
    }
    danlink l(a,i);
    i=0;
    while(cin>>n,n)
    {
        a[++i]=n;
    }
    danlink m(a,i,0);
    int p,q;
   cin>>p>>q;
    l.print();
    m.print();
 
    if(l.valuee(p))
    {
        l.print();
    }
    else
        cout<<"Error"<<endl;
    if(l.place(q))
        l.print();
    else
        cout<<"Error"<<endl;
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值