【发布时间】:2018-08-19 11:14:03
【问题描述】:
我正在尝试更改堆栈的顶部指针。
1) 直接更改指针工作正常。并相应更改传递的指针。
root = root -> next;
2) 但是在取消引用指针然后在本地更改它并不会更改指针。
Node* root = *top;
root = root -> next
函数定义:
int pop(Node** top)
{
if(isEmpty(*top))
return -1;
Node* temp = *top
int popped_data = temp-> data;
Node* root = *top;
//root = root -> next; // This is not modifying the actual pointer passed
*top = (*top)->next; // This is working fine. top is changed
delete temp;
return popped_data;
}
【问题讨论】:
-
那么,这是出于学术学习目的还是有其他原因不使用 C++ 标准容器?
标签: c++ pointers linked-list stack