赞
踩
- #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;
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。