lundi 15 mai 2023

prog.cpp:49:9: error: expected initializer before * token Node*insertAtEnd(Node *head, int x) { ^ [closed]

class Solution{
  public:
    //Function to insert a node at the beginning of the linked list.
    Node *insertAtBegining(Node *head, int x) {
       Node *curr = new Node(x);
       curr->next=head;
       return curr;
     }
    }
    
    
    //Function to insert a node at the end of the linked list.
    Node *insertAtEnd(Node *head, int x)  {
      
        if(head==NULL){
            Node *curr=Node(x);
            return curr;
            
        }
        Node *curr=head;
        while(curr->next!=NULL){
            curr=curr->next;
        }
        curr-next=new Node(x);
        return head;
    }
};

I don't understand the error.

Aucun commentaire:

Enregistrer un commentaire