fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Node{
  5. int key;
  6. Node *next , *prev;
  7. };
  8.  
  9. Node *nil;
  10.  
  11. void init(){
  12. nil = (Node *)malloc(sizeof(Node));
  13. nil -> next = nil;
  14. nil -> prev = nil;
  15. }
  16.  
  17. void insert(int key){
  18. Node *x = (Node *)malloc(sizeof(Node));
  19. x -> key = key;
  20. x -> next = nil -> next;
  21. nil -> next -> prev = x;
  22. nil -> next = x;
  23. x -> prev = nil;
  24. }
  25.  
  26. Node* listsearch(int key){
  27. Node *cur = nil -> next;
  28. while(cur != nil && cur -> key = key){
  29. cur = cur -> next;
  30. }
  31. return cur;
  32. }
  33.  
  34. void deleteNode(Node *t){
  35. if(t == nil) return;
  36. t -> prev -> next = t -> next;
  37. t -> next -> prev = t -> prev;
  38. free(t);
  39. }
  40.  
  41. void deletefirst(){
  42. deleteNode(nil -> next);
  43. }
  44.  
  45. void deletelast(){
  46. deleteNode(nil -> prev);
  47. }
  48.  
  49. void deletekey(int key){
  50. deleteNode(listsearch(key));
  51. }
  52.  
  53. void printlist(){
  54. Node *cur = nil -> next;
  55. int isf = 0;
  56. while(1){
  57. if( cur == nil ) break;
  58. if( isf++ > 0 ) printf(" ");
  59. printf("%d" , cur->key);
  60. cur = cur -> next;
  61. }
  62. printf("\n");
  63. }
  64.  
  65. int main() {
  66. int key, n , i;
  67. int size=0;
  68. char com[20];
  69. int np = 0 , nd = 0;
  70. scanf("%d",&n);
  71. init();
  72. for(i = 0 ; i < n ; i++){
  73. scanf("%s%d", com, &key);
  74. if( com[0] == 'i' ){ insert(key); np++ ; size++;}
  75. else if( com[0] == 'd' ) {
  76. if( strlen(com) > 6 ) {
  77. if( com[6] == 'F' ) deletefirst();
  78. else if( com[6] == 'L') deetelast();
  79. } else {
  80. deletekey(key); nd++;
  81. }
  82. size--;
  83. }
  84. }
  85.  
  86. printlist();
  87.  
  88. return 0;
  89. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘Node* listsearch(int)’:
prog.cpp:28:35: error: lvalue required as left operand of assignment
  while(cur != nil && cur -> key = key){
                                   ^~~
prog.cpp: In function ‘int main()’:
prog.cpp:78:39: error: ‘deetelast’ was not declared in this scope
     else if( com[6] == 'L') deetelast();
                                       ^
stdout
Standard output is empty