C++单链表程序没问题可运行,但显示段错误


#include<iostream>
using namespace std;
struct list{
    int data;
    list *next;
};
int main()
{   
    list *head;
    int n;
    cin>>n;
    list a[n];
    head=&a[0];
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i].data;
        a[i].next=&a[i+1];
      }
    cin>>a[n-1].data;
    a[n-1].next=NULL;
    int m,t,k,d,tempt=0;
    cin>>m;
    list *pl=head;
    for(int q=0;q<m;q++)
    {   
        cin>>t;
        if(t==0)
        {   
            cin>>k>>d;
            if(k==0)
            {
                list *temp=new list;
                temp->data=d;
                temp->next=head;
                head=temp;
                pl=head;
                tempt++;
            }
            else if(k>(n+tempt))
            continue;
            else
            {
            for(int h=1;h<k;h++)
            pl=pl->next;
            list *temp=new list;
            temp->data=d;
            temp->next=pl->next;
            pl->next=temp;
            pl=head;
            tempt++;
            }
            
            
        }
        else
        {
            cin>>k;
            if(k==0)
            continue;
            else{
            
            for(int h=1;h<k-1;h++)
            pl=pl->next;
            pl->next=pl->next->next;
            pl=head;
        }
        }
        
    }

    for(;pl->next!=NULL;)
    {
        cout<<pl->data<<' ';
        pl=pl->next;
    }
    cout<<pl->data<<' ';
    return 0;
}

把错误详细信息发出来看看。