Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Node {
- friend class List;
- public:
- Node()
- {
- next=NULL,prev=NULL;
- data=NULL;
- }
- char data;
- Node *next, *prev;
- };
- class List
- {
- public:
- Node * head;
- Node *tail;
- Node *cur;
- int size = 0;
- List()
- {
- head = NULL, tail = NULL, size = 0;
- cur=NULL;
- }
- void Insert(char data)
- {
- Node *newNode = new Node;
- newNode->data = data;
- if (head == NULL)
- {
- head = newNode;
- tail = newNode;
- head->next=NULL;
- head->prev = NULL;
- size++;
- }
- else
- {
- tail->next = newNode;
- newNode->prev = tail;
- tail = newNode;
- newNode->next = NULL;
- size++;
- }
- }
- };
- void fuc();
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- int N;
- cin>>N;
- cin.get();
- for(int i=1;i<=N;i++)
- {
- fuc();
- }
- return 0;
- }
- void fuc()
- {
- List list=List();
- while(true)
- {
- /*Node* x;
- x=list.head;
- while(true)
- {if(x==NULL)
- {
- cout<<"\n";
- break;
- }
- if(list.cur==x)
- cout<<x->data<<".";
- else
- cout<<x->data;
- x=x->next;
- }*/
- char temp;
- temp=cin.get();
- if(temp=='<')
- {
- if(list.cur==NULL) continue;
- list.cur=list.cur->prev;
- }
- else if(temp=='>')
- {
- if(list.cur==list.tail) continue;
- if(list.cur==NULL)
- list.cur=list.head;
- else
- list.cur=list.cur->next;
- }
- else if(temp=='\n')
- {
- Node* x;
- x=list.head;
- while(true)
- {
- cout<<x->data;
- x=x->next;
- if(x==NULL)
- {
- cout<<"\n";
- break;
- }
- }
- break;
- }
- else if(temp=='-')
- {
- if(list.size==1)
- {
- if(list.cur==list.head)
- {
- list.size--;
- list.tail=NULL;
- list.head=NULL;
- list.cur=NULL;
- }
- }
- else if(list.size==0)
- {
- continue;
- }
- else
- {
- if(list.cur==NULL) continue;
- list.size--;
- if(list.cur==list.head)
- {
- list.head->next->prev=NULL;
- list.head=list.head->next;
- list.cur=NULL;
- }
- else if(list.cur==list.tail)
- {
- list.tail->prev->next=NULL;
- list.tail=list.tail->prev;
- list.cur=list.tail;
- }
- else
- {
- list.cur->prev->next=list.cur->next;
- list.cur->next->prev=list.cur->prev;
- list.cur=list.cur->prev;
- }
- }
- }
- else
- {
- if(list.size==0)
- {
- list.Insert(temp);
- list.cur=list.tail;
- continue;
- }
- Node *nn=new Node();
- nn->data=temp;
- list.size++;
- if(list.cur==NULL)
- {
- nn->prev=NULL;
- nn->next=list.head;
- list.head->prev=nn;
- list.head=nn;
- list.cur=list.head;
- }
- else if(list.cur==list.tail)
- {
- list.tail->next=nn;
- nn->prev=list.tail;
- nn->next=NULL;
- list.tail=nn;
- list.cur=list.tail;
- }
- else
- {
- list.cur->next->prev=nn;
- nn->next=list.cur->next;
- list.cur->next=nn;
- nn->prev=list.cur;
- list.cur=list.cur->next;
- }
- }
- }
- }
- //f<->--><-l>>d---u-j><>-<u->xb<<axkh<-wk>k>--t--s<b<i<ir>--ey>t>>sx<-yb<>jw<-qaruwy<osnshf><<<-uzz--<
Add Comment
Please, Sign In to add comment