首页 > 其他 > 详细

单链表1(悲剧文本)

时间:2018-05-12 13:04:17      阅读:267      评论:0      收藏:0      [点我收藏+]
#include"iostream"
using namespace std;
typedef char element;
class List{
private:
    element data;
    
public:List *next;
    List(int data = 0){
        this->data = data;
        this->next = NULL;
    }
    void deleteNote(){            //删除后一个结点
        List *temp = this->next;
        this->next = this->next->next;
        delete temp;
    }
    void show(){
        List *p = this->next;
        while(p){
            cout<<p->data;
            p = p->next;
        }
        cout<<endl;
    }
    List *insertf(element data){
        List *newp = new List(data);
        if(!newp){
            cout<<"out of space!"<<endl;
            return NULL;
        }
        newp->next = this->next;
        this->next = newp;
        return newp;
    }
    List *insertl(element data){
        List *newp = new List(data);
        if(!newp){
            cout<<"out of space!"<<endl;
            return NULL;
        }
        List *last = this;
        while(last->next){
            last = last -> next;
        }
        newp->next = last->next;
        last->next = newp;
        return newp;
    }
    void recover(char *s){
        int i = 0;
        List *p = this;
        while(s[i]!=\0){
            if(s[i]==[){
                p = this->insertf(s[++i]);
            }
            else if(s[i] == ]){
                p = p->insertl(s[++i]);
            }
            else{
                p = p->insertf(s[i]);
            }
            i++;
        }
    }
};
    
//kdg[gek]h[itj
//de[co]vs
int main(){
    List L,*p = &L;
    char *str = "kdg[gek]h[itj";
    L.recover(str);
    L.show();
    return 0;
}

 

单链表1(悲剧文本)

原文:https://www.cnblogs.com/oleolema/p/9028397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!