码迷,mamicode.com
首页 > 其他好文 > 详细

单链表1(悲剧文本)

时间:2018-05-12 13:15:27      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:next   ace   space   ios   public   let   nbsp   last   over   

#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(悲剧文本)

标签:next   ace   space   ios   public   let   nbsp   last   over   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!