c++ - 堆栈操作(主函数)
问题描述
所以我在 C++ 中实现了 Stack 的基本操作。我编写了函数,但我不知道如何实现 main 函数以便从堆栈中查看值。
头文件
#ifndef HEADER_H_
#define HEADER_H_
#define DIM 15
typedef int Atom;
struct Element {
Atom data;
Element *link;
};
typedef Element* LinkedStack;
void initS(LinkedStack &S);
void push(LinkedStack &S, Atom a);
bool isEmpty2(LinkedStack &S);
void pop2(LinkedStack &S);
Atom top2(Stack &S);
#endif
函数文件
void initS(LinkedStack &S)
{
S = nullptr;
}
void push(LinkedStack &S, Atom a)
{
Element*nou = new Element;
nou->data = a;
nou->link = S;
S = nou;
}
bool isEmpty2(LinkedStack &S)
{
if (S == 0)
return true;
else return false;
}
void pop2(LinkedStack &S)
{
LinkedStack aux = S;
S = S->link;
delete(aux);
}
Atom top2(LinkedStack &S)
{
if (isEmpty2(S))
return Atom();
return S->data;
}
我是如何实现主要功能的。我不知道如何查看值,例如如果我写 cout<
#include <iostream>
#include "header.h"
using namespace std;
int main()
{
LinkedStack S;
initS(S);
push(S, 2);
push(S, 4);
push(S, 6);
push(S, 7);
push(S, 10);
return 0;
}
After I compile the program I don't see nothing in console.How to see the values from stack?
解决方案
推荐阅读
- php - 使用 PHP 加载 MySQL 数据但结果格式错误
- google-cloud-platform - Google Cloud DNS MX 记录返回值错误
- c# - 在 C# 中读取二进制类型的 Azure Blob
- postgresql - 如何将数据从 csv 导入具有 auto_increment 第一列或字段的 postgresql 表
- python-3.x - 如何拆分二维列表中的字符串?
- azure - 如何通过 Ansible 模块获取 Azure 订阅详情?
- ms-access - Access 数据库报告:按数字值对字符字段排序,然后按 1 个字段中的字符排序
- javascript - 如何使用 JSP 和 Javascript 从数据库生成实时图形
- javascript - 如何找出由 tinyMCE 中的更改文本颜色按钮触发的操作以及如何将其与我的自定义按钮链接?
- c# - 如果用户未获得授权,则返回较少的数据