为什么最后会疯狂输出地址?要怎么更改?

两个链表的合并成一个链表,用−1表示序列的结尾(−1不属于这个序列)


#include<iostream>
#include<malloc.h>
using namespace std;
typedef struct node{
    int data;
    node *next;
}LinkListNode;
int main(){
    int x;
    LinkListNode *head,*node,*p;
    head=(LinkListNode*)malloc(sizeof(LinkListNode)) ;
    cin>>x;
    head->data=x;
    head->next=NULL;
    p=node=head;
    while(x!=-1){
        cin>>x;
        if(x==-1){
            break;
        }
        node=(LinkListNode*)malloc(sizeof(LinkListNode));
        node->data=x;
        p->next=node;
        p=node;
    }
    LinkListNode *head_,*node_,*p_;
    head_=(LinkListNode*)malloc(sizeof(LinkListNode));
    cin>>x;
    head_->data=x;
    head_->next=NULL;
    p_=node_=head_;
    while(x!=-1){
        cin>>x;
        if(x==-1){
            break;
        }
        node_=(LinkListNode*)malloc(sizeof(LinkListNode));
        node_->data=x;
        p_->next=node_;
        p_=node_;
    }
    node->next=head_;
    p=head;
    while(p){
        cout<<p->data<<" "; 
        p=p->next;
    }
    
}

img

两个node->next=null加上