C++数据结构
把链栈想象成单链表头结点的后插和后删操作
不带头结点的链栈
//不带头结点的链栈
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
typedef struct Linknode1 {
int data;
struct Linknode1* next;
}*LiStack1;
void InitStack1(LiStack1& L) {
L= NULL;
}
//进栈
LiStack1 Push1(LiStack1& L, int x) {
Linknode1* s = (LiStack1)malloc(sizeof(Linknode1));
s->data = x;
s->next = L;
L= s;
return L;
}
//出栈
bool Pop1(LiStack1 & L) {
if (L == NULL) {
return false;
}