c++ - 进程终止,状态为-1073741510

标签 c++ compiler-errors linked-list

我已经编写了一个C++程序,将插入到排序的链表中-给出错误:进程终止,状态为-1073741510 我在这里使用了双指针来访问头节点。
程序中没有其他错误

#include<iostream>
using namespace std;
struct node
{
    int data;
    struct node* next;    
};
 void ins(int d,node** head)
{
   node* temp=new node;
   node* prev=new node;
   temp->next=NULL;
   temp->data=d;
   if(head==NULL)
    {
        *head=temp;
    }
    else
    {
        node* ptr=*head;
        while(ptr!=NULL && ptr->data<d)
        {   prev=ptr;
            ptr=ptr->next;
        }
        prev->next=temp;
        temp->next=ptr;    
    }  
}
void print(node* head)
{
    node* ptr=head;int i=0;
    while(ptr!=NULL)
   {
    cout<<i<<" "<<ptr->data<<" ";
    i++;
    ptr=ptr->next;
  }
}
int main()
{
 node* head=NULL;
 ins(4,&head);
 ins(10,&head);
 ins(9,&head);
 print(head);
 return 0;
}`

最佳答案

您在if (head == NULL)中输入了错误,因为head根本不应该为null,所以它应该是if (*head == NULL)。但这不应该导致进程终止。

关于c++ - 进程终止,状态为-1073741510,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37904427/

相关文章:

c++ - __next_prime 符号未定义

c++ - 在 C++ 中以编程方式将资源加载为字节数组

compiler-errors - 在 Solaris_x86 上构建 OpenSSL 时,Assembler 报告非法助记符

c - 需要对名称链接列表进行合并排序

java - 为什么 LinkedList 在 java 中没有 initialCapacity?

for 循环 NullPointerException 中的 Java 迭代器

c++ - 违反封装?

C++ 打开文件并向类对象输入数据

c++ - 使用模板化适配器作为运算符重载实例的 rhs 编译错误

c++ - g++ 在 *expected* 错误消息中给我奇怪的函数调用