void push(stack *head, int valuee)
{
if(head->next==NULL && head->value==-1)
{
head->value = valuee;
printf("First element %d inserted\n",valuee);
}
else
{
stack *temp = new stack;
temp->value = valuee;
temp->next = head;
head = temp;
printf("Element %d inserted\n",valuee);
}
}
第一个元素已正确插入,但当我继续插入元素时,在第一个元素之后没有插入任何元素。 在某个地方读到我必须将指针传递给堆栈指针,但我在后缀中缀问题中做了同样的事情并且它在那里工作。 在这里帮我解决这个问题。 非常感谢您提前提供帮助
中缀后缀的前一个例子很好用
void push(char c, stack *node)
{
stack *B = (stack *)malloc(sizeof(stack));
if (node->next == NULL)
{
node->next = B;
B->value = c;
B->next =NULL;
}
else
{
B->next = node->next;
node->next = B;
B->value = c;
}
}
最佳答案
你可以这样改变函数
stack* push(stack *head, int valuee)
//return void to stack *
return head;
//In the end return the new head
它会起作用的。 像这样调用推送
head = push(head,value);
关于c - 压栈不插入新值 - C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20613273/