// 采用指针链表操作
struct selected_pixel
{
int pixel_x;
int pixel_y;
struct selected_pixel * next;
}; struct selected_pixel curr_pixel;struct selected_pixel * p_head, * p_tail, * new_p, * p_ori;
p_ori = p_head = p_tail = &curr_pixel;
之后进行了一系列的操作,操作完成后,我想把链表占用的内存释放掉。于是
while(p_ori)
{
new_p=p_ori;
p_ori=p_ori->next;
delete new_p;
} 每次运行到delete new_p;的时候就会出现user breakpoint called from code at 0x7c921230,
难道是不能用delete 吗??请教各位大虾了。
struct selected_pixel
{
int pixel_x;
int pixel_y;
struct selected_pixel * next;
}; struct selected_pixel curr_pixel;struct selected_pixel * p_head, * p_tail, * new_p, * p_ori;
p_ori = p_head = p_tail = &curr_pixel;
之后进行了一系列的操作,操作完成后,我想把链表占用的内存释放掉。于是
while(p_ori)
{
new_p=p_ori;
p_ori=p_ori->next;
delete new_p;
} 每次运行到delete new_p;的时候就会出现user breakpoint called from code at 0x7c921230,
难道是不能用delete 吗??请教各位大虾了。
解决方案 »
- [ 毕业设计系列问题-3 ]变量的作用范围
- ***请高手赐教:水晶报表问题,动态查询筛选记录的问题,急用,在线等待...***
- 哪有vc++ 7.0 的下载
- 如何让图片框显示jpg文件
- 哪位大虾有canny法边缘检测的vc源程序,急!!!!!!!!!
- VC, text 文本请教!
- 《有自己的软件被OEM经验的看过来!!》请教!!请教!!!
- VC++和MySQL的问题讨论!! 100分奉献!
- 在使用CFile类的Write函数的时候有一个问题(300分)又开贴了
- 客户机访问服务器server2000 出问题(谁解决了再送100分)
- 一个奇怪CAsyncSocket的Connect阻塞问题
- 如何在程序中将a文件另存为b文件?
但是你的*new_p 当指向 curr_pixel时候,使用 delete new_p就是错误的。
且如果->next为指向null的时候不需要使用delete链表的操作
http://www.diybl.com/course/3_program/c/c_js/2007109/77271.html
while( p_head != NULL)
{
curr_i = p_head->pixel_x;
curr_j = p_head->pixel_y;
if ( ( curr_i > 1 && curr_i < height-1) && ( curr_j >1 && curr_j < width-1) )
{
top_point = (curr_i-1)*width + curr_j;
bottom_point = (curr_i+1)*width + curr_j;
left_point = curr_i*width + curr_j-1;
right_point = curr_i*width + curr_j+1; if ( YOUT[top_point] == 255 )
{
*total_pixel_num += 1;
YOUT[top_point] = area_label_no;
new_p = new selected_pixel[1];
p_tail->next = new_p;
new_p->pixel_x = curr_i-1;
new_p->pixel_y = curr_j;
new_p->next = NULL;
p_tail = p_tail->next;
}
if ( YOUT[bottom_point] == 255 )
{
*total_pixel_num += 1;
YOUT[bottom_point] = area_label_no;
new_p = new selected_pixel[1];
p_tail->next = new_p;
new_p->pixel_x = curr_i+1;
new_p->pixel_y = curr_j;
new_p->next = NULL;
p_tail = p_tail->next;
}
if ( YOUT[left_point] == 255 )
{
*total_pixel_num += 1;
YOUT[left_point] = area_label_no;
new_p = new selected_pixel[1];
p_tail->next = new_p;
new_p->pixel_x = curr_i;
new_p->pixel_y = curr_j-1;
new_p->next = NULL;
p_tail = p_tail->next;
}
if ( YOUT[right_point] == 255 )
{
*total_pixel_num += 1;
YOUT[right_point] = area_label_no;
new_p = new selected_pixel[1];
p_tail->next = new_p;
new_p->pixel_x = curr_i;
new_p->pixel_y = curr_j+1;
new_p->next = NULL;
p_tail = p_tail->next;
} }
p_head = p_head->next;
}