如何从堆栈末端删除0
How do I remove 0 from end of stack
函数处理字符串数组,并通过使用堆栈函数返回int值。在堆栈中,要推出的第一个数字是最后一个弹出的数字,因此循环从字符串的末端开始。它应该在字符串开始时删除任何0例如。004912500 => 4912500但是我不知道如何确保我的循环能够在开始时和0之后的0区分,因为炭都从背面推了。getvp返回void Pointer的整数值
int getDecimal (const char stringOfDigits [])
{
Stack S;
int *temp;
VoidPtr item;
// Loop to get int value of each element of char array
for (int i = strlen(stringOfDigits)-1; i >= 0; i--)
{
if (isdigit(stringOfDigits[i]))
{
if (stringOfDigits[i] != '0')
{
temp = new int;
*temp = (stringOfDigits[i] - '0');
item = temp;
S.push(item);
}
}
}
while(!S.isEmpty())
{
item = S.pop();
cout << S.getVP(item);
}
cout << endl;
}
在开始打印之前跳过0
int getDecimal (const char stringOfDigits [])
{
Stack S;
int *temp;
VoidPtr item;
int i = strlen(stringOfDigits)-1;
// Loop to get int value of each element of char array
for (; i >= 0; i--)
{
if (isdigit(stringOfDigits[i]))
{
if (stringOfDigits[i] != '0')
{
temp = new int;
*temp = (stringOfDigits[i] - '0');
item = temp;
S.push(item);
}
}
}
if(!S.isEmpty())
{
item = S.pop();
//skip the 0's
while((item == 0) && !S.isEmpty())
{
item = S.pop();
}
//output the first valid item, or a 0 if it's filled with 0
cout << S.getVP(item);
while(!S.isEmpty())
{
item = S.pop();
cout << S.getVP(item);
}
cout << endl;
}
相关文章:
- 双链表堆栈删除函数不起作用
- C++对自动(堆栈)指针使用运算符删除
- 使用链表在堆栈中插入和删除
- 如何从堆栈末端删除0
- 删除堆栈上声明的对象
- 使用卷曲支架从堆栈中删除分配
- 运行时检查失败#2 - 变量周围的堆栈'myArray'已损坏.- 似乎无法弄清楚如何删除此错误
- 指向堆栈对象的指针是否在超出范围时被删除
- C++不允许堆栈实例,但允许新的删除
- C++为什么创建一个新节点来删除堆栈上的节点是错误的
- 即使指针在函数堆栈中,我也必须删除它吗
- 从分配在堆栈上的对象指针的向量中删除元素
- Qt - 堆栈上具有父级的 QObject 如何被删除两次?
- C :删除在堆栈上声明的结构的字段
- 使用删除后指针是否指向堆栈或堆
- 我可以使用C++删除堆栈中的特定位置数据吗?
- 删除时,QObject是否区分堆栈和堆分配的子级
- 堆栈是如何组织的?:删除二叉树
- 删除具有堆栈指针的派生类
- _Block_Type_Is_Valid (pHead->nBlockUse) 删除堆栈内存?