#include<stdio.h>
#include<malloc.h>
typedef struct SNode {
int data;
struct SNode* next;
} *LinkStack;
void InitStack(LinkStack& stack) {
stack = (SNode*)malloc(sizeof(SNode));
stack->data = 0;
stack->next = NULL;
}
void push(LinkStack& stack, int data) {
SNode* s;
s = (SNode*)malloc(sizeof(SNode));
s->data = data;
s->next = stack;
stack = s;
}
void print(LinkStack stack) {
SNode* temp;
temp = stack;
while (temp != NULL) {
printf("%d\n", temp->data);
temp = temp->next;
}
printf("-------------------\n");
}
void pop(LinkStack& stack) {
if (stack==NULL) {
return;
}
stack = stack->next;
}
int main() {
LinkStack L;
InitStack(L);
for (int i = 1; i <= 10; i++) {
push(L, i);
}
print(L);
pop(L);
print(L);
}
链栈的入栈出栈
最新推荐文章于 2024-01-05 23:12:56 发布