fork download
  1. /*************
  2.  Following is the Node structure already written.
  3.  
  4.  template <typename T>
  5.  class Node {
  6. public:
  7. T data;
  8. Node* next;
  9.  
  10. Node(T data) {
  11.  next = NULL;
  12.  this->data = data;
  13. }
  14.  
  15. ~Node() {
  16.  if (next != NULL) {
  17.  delete next;
  18.  }
  19. }
  20.  };
  21.  
  22.  *************/
  23.  
  24.  
  25. Node<int>* deleteMid(Node<int> *head) {
  26. int len = 0;
  27. if(head == NULL){
  28. return NULL;
  29. }
  30. else{
  31. Node<int>*temp1 = head;
  32. while(temp1!=NULL){
  33. len++;
  34. temp1 = temp1->next;
  35. }
  36. Node<int>*temp = head;
  37. Node<int>*prev = NULL;
  38.  
  39. for(int i=0;i<(len)/2;i++){
  40. prev = temp;
  41. temp = temp->next;
  42. }
  43. prev->next = temp->next;
  44. delete temp;
  45. return head;
  46. }
  47.  
  48.  
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:25:1: error: ‘Node’ does not name a type
 Node<int>* deleteMid(Node<int> *head) {
 ^~~~
stdout
Standard output is empty