#include<iostream>
struct stackNode {
int date;
struct stackNode* next;
};
struct stackNode* createStackNode() {
struct stackNode* p = new stackNode;
if (p == nullptr) {
return nullptr;
}
p->next = nullptr;
return p;
}
void push(struct stackNode* node, int x) {
struct stackNode* temp = new stackNode;
if (temp == nullptr) {
return;
}
else {
temp->next = node->next;
temp->date = x;
node->next = temp;
}
}
void pop(struct stackNode* node) {
if (node == nullptr) {
return;
}
else {
struct stackNode* temp = node->next;
node->next = node->next->next;
free(temp);
}
}
bool isEmpty(struct stackNode* node) {
return node->next == NULL;
}
int getSize(struct stackNode* node) {
int count = 0;
struct stackNode* p = node->next;
while (p) {
count++;
p = p->next;
}
return count;
}
int getTop(struct stackNode* node) {
if (node == nullptr) {
return -1;
}
else {
return node->next->date;
}
}
void printStack(struct stackNode* node) {
struct stackNode* p = node->next;
while (p) {
std::cout << p->date<<std::endl;
p = p->next;
}
return;
}
void makeEmpty(struct stackNode* node) {
if (node == nullptr) {
return;
}
while (!isEmpty(node)) {
pop(node);
}
}
int main() {
return 0;
}
数据结构与算法-链栈
最新推荐文章于 2024-05-20 15:29:54 发布