有人可以帮助我了解在下列功能中发生了什么? 具体使用s1-> top?而s1-> top在功能上的动作是什么,按& pop &显示?因为如果在功能推动中,每当一个数字被推动时,s1-> top向右移动?那么为什么在显示功能中,它表示s1-> top在遍历中是第一个,而在s1-> top中是n在右边,而在打印值时,我们需要先在左边然后遍历。为什么?有人可以帮助我了解在下列功能中发生了什么?
Stack createStack() {
Stack s1;
s1 = (Stack) malloc(sizeof(Stack_Head));
s1 - > count = 0;
s1 - > top = NULL;
return s1;
}
Nodeptr createNode(dataitem item) {
Nodeptr temp;
temp = (Nodeptr) malloc(sizeof(Node));
temp - > data = item;
temp - > next = NULL;
return temp;
}
void push(Stack s1, dataitem item) {
Nodeptr temp = createNode(item);
temp - > next = s1 - > top;
s1 - > top = temp;
s1 - > count++;
}
void display(Stack s1) {
Nodeptr ptr = s1 - > top;
while (ptr1 = NULL) {
printf("%d", ptr - > data);
ptr = ptr - > next;
}
printf("\n");
}
void pop(Stack s1) {
Nodeptr temp;
if (isEmpty(s1))
printf("List is Empty");
else {
temp = s1 - > top;
s1 - > top = temp - > next;
temp - > next = NULL;
free(temp);
s1 - > count;
}
int isEmpty(Stack s1) {
return s1 - > top == NULL;
}
你想看看'Stack'类型的定义。 – alk
由于可怕的缩进,我没有阅读代码。 –
你的意思是' - >'运算符吗?你不知道它是什么?也许你应该阅读[点(。)运算符和 - >在C++中有什么区别?](http://stackoverflow.com/questions/1238613/what-is-the-difference-between-the-dot- operator-and-in-c)(如果这是主要问题,可能应该将其投票重复)。 –