单链表1(悲剧文本)
Posted O了吗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单链表1(悲剧文本)相关的知识,希望对你有一定的参考价值。
#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(悲剧文本)的主要内容,如果未能解决你的问题,请参考以下文章