#include
using namespace std;
class node {
public:
int data;
node*next;
node(int d) {
data=d;
next=NULL;
}
};
void insertAthead( node*&head,int d) {
if(head==NULL) {
head=new Node(d);
return;
}
Node *n=new Node(d);
n->next=head;
head=n;
}
void print(node*head) {
while(head!=NULL) {
cout<data<<"->";
head=head->next;
}
cout<<endl;
}
int main() {
node*head=NULL;
insertAthead(head,3);
insertAthead(head,2);
insertAthead(head,1);
insertAthead(head,0);
print(head);
return 0;
}
error
link.cpp: In function ‘void insertAthead(node*&, int)’:
link.cpp:15:18: error: expected type-specifier before ‘Node’
head=new Node(d);
^~~~
link.cpp:18:5: error: ‘Node’ was not declared in this scope
Node *n=new Node(d);
Node *n=new Node(d);
^~~~
node
link.cpp:18:11: error: ‘n’ was not declared in this scope
Node *n=new Node(d);
^
link.cpp:18:17: error: expected type-specifier before ‘Node’
Node n=new Node(d);
^~~~
PS C:\backupppp\cpp coding\linked list> cd “c:\backupppp\cpp coding\linked list” ; if (?) { g++ -std=c++14 link.cpp -o link } ; if (?) {
.\link }
link.cpp: In function 'void insertAthead(node&, int)’:
link.cpp:15:18: error: expected type-specifier before ‘Node’
head=new Node(d);
^~~~
link.cpp:18:5: error: ‘Node’ was not declared in this scope
Node *n=new Node(d);
^~~~
link.cpp:18:5: note: suggested alternative: ‘node’
Node *n=new Node(d);
^~~~
node
link.cpp:18:11: error: ‘n’ was not declared in this scope
Node *n=new Node(d);
^
link.cpp:18:17: error: expected type-specifier before ‘Node’
Node *n=new Node(d);
i have done everything same as video but why so error