I'm tryin to create a program that let me add elements in tail of a list and then prints them. It doesn't give me an error but he doesn't do anything. What am I doing wrong ?
#include<iostream>
using namespace std;
struct lista{
int val;
lista *next;
};
typedef lista* ptr_lista;
void tail_add(ptr_lista head, int valore){
if(head=NULL){
head=new lista;
head->val=valore;
head->next=NULL;
} else {
ptr_lista p=head;
while(p->next!=NULL){
p=p->next;
}
p->next=new lista;
p->next->val=valore;
p->next->next=NULL;
}
}
void print(ptr_lista p){
while(p!=NULL){
cout<<p->val<< " ";
p=p->next;
}
}
int main(){
ptr_lista m;
tail_add(m,5);
tail_add(m,6);
print(m);
}