agntsrvc.exe 中的 0x0012e85c 处未处理的异常: 0xC0000005: 读取位置 0x00000000 时发生访问冲突

来源:百度知道 编辑:UC知道 时间:2024/09/20 22:39:23

#include "stdafx.h"
#include<iostream>
struct node
{
int a;
node* next;
};

int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;

int temp;
cin>>temp;
node* head,*rear;
head=rear=NULL;

while(temp){
node *p = new node;//操作指针前要先给指针赋值,这里分配内存
if(p == null)
{
cout>>"分配内存失败!"<<endl;
break;
}
p->a = temp;
p->next = NULL;

if(head==null)//第一个,保存链表头指针,尾指针
{
head = p;
rear = p;
}
else
{
rear->next = p;//调整尾指针
rear = rear->next;
}

cout<<"Please cin next Elem!\n";
cin>>temp; //输入下一个数,0退出
}

//释放内存
while(head)
{
node *p = head;
head = head->next;//下一个
delete p;//释放
}

cout<<endl<<"OK!";
c