Im试着实现一个推送前端方法到C++双端队列。我做这件事的方式是移动数组中的每个元素。它工作,但我的程序最终崩溃!在我的推前台方法中,我似乎“跑过我的阵列的末尾”,导致堆损坏错误,调试断言,这些事情..push_front C++用户实现
我还没有能够开发push_front实现而不移动数组。
stack::stack(capacity) : items(new item[capacity]), front(*items), maxSize(capacity-1)
{
top = -1;
}
bool stack::pushFront(const int nPushFront)
{
if (count == maxSize) // indicates a full array
{
return false;
}
for (int entry_int = 0; entry_int < count;) // loop less than however many we count.
{
if (entry_int == top+1)
{
front.n = items[top+1].n;
}
items->n = items[++entry_int].n;
items[entry_int].n = front.n;
front.n = items[++entry_int].n;
items[entry_int].n = items->n;
}
++count;
items[top+1].n = nPushFront;
return true;
}
任何人都可以帮忙吗?
我aplogize的格式,所以我张贴之前看起来很好。 – user40120 2009-10-29 21:03:24
随时修复它 – 2009-10-29 21:17:18
发布前删除标签。 – 2009-10-29 21:36:59