链表问题(基础性的)

麻烦大家帮我看看,学编程没多久,问问这个为什么错的(应该是删除有问题),万分感谢;
另外代码有不好的地方也希望大家指出来,真的想进步一点

#include 
using namespace std;
struct node{
    int number=0;
    node *next;
};
//后插法  没有用到
void creatList(node *L){
    node *p=L;
    int a=0;
    cin>>a;
    while (a!=-1) {
        node *n=new node ();
        n->next=NULL;
        n->number=a;
        p->next=n;
        
        p=p->next;
        cin>>a;
    }
}

//前插法

void createList2(node *L){

    int a=0;
    cin>>a;
    while (a!=-1) {
       node *n=new node ();
       n->next=nullptr;
       n->number=a;
       n->next=L->next;
       L->next=n;
       cin>>a;
    }
}

void deleteNode(node *L,int a){
   node *p=L;
   while (p->next!=nullptr) {

       if(p->next->number==a){
           p->next=p->next->next;
   }
        p=p->next;
    }
   free(p);

}
void printList(node *L){

    node *p=L;
    while (p->next!=nullptr) {
        cout<next->number<<" ";//易错点
        p=p->next;//易错点
    }
}

int main(){
    node *L=new node ();
    L->next=NULL;
    createList2(L);
    int a=0;
    cin>>a;
    deleteNode(L,a);

    printList(L);

    return 0;
}

img



void deleteNode(node *L,int a){
   node *p=L;
   node *q = NULL;
   while (p->next!=nullptr) {
       if(p->next->number==a){
           q = p->next;
           p->next=p->next->next;
           free(q);
           break;
        }
        p=p->next;
    }

 
}