Guest User

Untitled

a guest
Jul 13th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Node {
  5. friend class List;
  6.  
  7. public:
  8. Node()
  9. {
  10. next=NULL,prev=NULL;
  11. data=NULL;
  12. }
  13. char data;
  14. Node *next, *prev;
  15. };
  16.  
  17. class List
  18. {
  19.  
  20. public:
  21. Node * head;
  22. Node *tail;
  23. Node *cur;
  24. int size = 0;
  25. List()
  26. {
  27. head = NULL, tail = NULL, size = 0;
  28. cur=NULL;
  29. }
  30. void Insert(char data)
  31. {
  32. Node *newNode = new Node;
  33. newNode->data = data;
  34.  
  35. if (head == NULL)
  36. {
  37. head = newNode;
  38. tail = newNode;
  39. head->next=NULL;
  40. head->prev = NULL;
  41. size++;
  42. }
  43. else
  44. {
  45. tail->next = newNode;
  46. newNode->prev = tail;
  47. tail = newNode;
  48. newNode->next = NULL;
  49. size++;
  50. }
  51. }
  52. };
  53.  
  54. void fuc();
  55.  
  56. int main()
  57. {
  58. ios::sync_with_stdio(false);
  59. cin.tie(NULL);
  60. int N;
  61. cin>>N;
  62. cin.get();
  63. for(int i=1;i<=N;i++)
  64. {
  65. fuc();
  66. }
  67. return 0;
  68. }
  69.  
  70. void fuc()
  71. {
  72. List list=List();
  73.  
  74. while(true)
  75. {
  76. /*Node* x;
  77. x=list.head;
  78. while(true)
  79. {if(x==NULL)
  80. {
  81. cout<<"\n";
  82. break;
  83. }
  84. if(list.cur==x)
  85. cout<<x->data<<".";
  86. else
  87. cout<<x->data;
  88. x=x->next;
  89.  
  90. }*/
  91. char temp;
  92. temp=cin.get();
  93. if(temp=='<')
  94. {
  95. if(list.cur==NULL) continue;
  96. list.cur=list.cur->prev;
  97.  
  98. }
  99. else if(temp=='>')
  100. {
  101. if(list.cur==list.tail) continue;
  102. if(list.cur==NULL)
  103. list.cur=list.head;
  104. else
  105. list.cur=list.cur->next;
  106. }
  107. else if(temp=='\n')
  108. {
  109. Node* x;
  110. x=list.head;
  111. while(true)
  112. {
  113. cout<<x->data;
  114. x=x->next;
  115. if(x==NULL)
  116. {
  117. cout<<"\n";
  118. break;
  119. }
  120. }
  121. break;
  122. }
  123. else if(temp=='-')
  124. {
  125. if(list.size==1)
  126. {
  127. if(list.cur==list.head)
  128. {
  129. list.size--;
  130. list.tail=NULL;
  131. list.head=NULL;
  132. list.cur=NULL;
  133. }
  134. }
  135. else if(list.size==0)
  136. {
  137. continue;
  138. }
  139. else
  140. {
  141. if(list.cur==NULL) continue;
  142.  
  143. list.size--;
  144. if(list.cur==list.head)
  145. {
  146. list.head->next->prev=NULL;
  147. list.head=list.head->next;
  148. list.cur=NULL;
  149. }
  150. else if(list.cur==list.tail)
  151. {
  152. list.tail->prev->next=NULL;
  153. list.tail=list.tail->prev;
  154. list.cur=list.tail;
  155. }
  156. else
  157. {
  158. list.cur->prev->next=list.cur->next;
  159. list.cur->next->prev=list.cur->prev;
  160. list.cur=list.cur->prev;
  161. }
  162. }
  163. }
  164. else
  165. {
  166. if(list.size==0)
  167. {
  168. list.Insert(temp);
  169. list.cur=list.tail;
  170. continue;
  171. }
  172. Node *nn=new Node();
  173. nn->data=temp;
  174. list.size++;
  175. if(list.cur==NULL)
  176. {
  177. nn->prev=NULL;
  178. nn->next=list.head;
  179. list.head->prev=nn;
  180. list.head=nn;
  181. list.cur=list.head;
  182. }
  183. else if(list.cur==list.tail)
  184. {
  185. list.tail->next=nn;
  186. nn->prev=list.tail;
  187. nn->next=NULL;
  188. list.tail=nn;
  189. list.cur=list.tail;
  190. }
  191. else
  192. {
  193. list.cur->next->prev=nn;
  194. nn->next=list.cur->next;
  195. list.cur->next=nn;
  196. nn->prev=list.cur;
  197. list.cur=list.cur->next;
  198. }
  199. }
  200. }
  201. }
  202. //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