append function nodes in c++…. (stuck in errors) [closed]

#include<bits/stdc++.h>

using namespace std;

// Linked List Node

class Node

{

public:
int data; // Data

Node *next; // Pointer

Node(int x)

{

data=x;

next=NULL;

}

};


void append(Node **head, int val)

{

Node temp;

if(head==NULL)

{

head=new Node(val);

temp=head;

}

else

{

temp->next=new Node(val);

temp=temp->next;

}

}


// This function prints contents of linked list
// starting from the given node
void printList(Node node)

{

while (node != NULL)

{

cout<<node->data<<" ";


node = node->next;

}

}

// Program to create a simple linked list

int main()
{

Node head = NULL;

append(&head,2);

append(&head,3);

append(&head,4);

append(&head,5);


printList(head);

return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT