C++之Stack
来源:互联网 发布:剑三捏脸成男数据 贴 编辑:程序博客网 时间:2024/05/01 09:49
#include "iostream"
using namespace std;
class Cstack
{
int *top;
int *bottom;
public:
Cstack()
{ top = bottom = new int[100]; }
void Push(int c)
{
if ((top - bottom) < 100)
*top ++=c;
}
int Pop()
{
if(--top >= bottom)
return *top;
}
~Cstack()
{ delete top;}
};
char * ReverseName(char *name)
{
Cstack s;
char *reverse;
for (int i=0; i<strlen(name); i++)
s.Push(name[i]);
reverse = new char[strlen(name) + 1];
for(int i = 0; i < strlen(name); i++)
reverse[i] = s.Pop();
reverse[strlen(name)] = '\0';
return reverse;
}
void main()
{
char str[20];
cout << "输入字符串: ";
cin >> str;
cout << "该字符串的反序为: "<<ReverseName(str)<<'\n';
system("pause");
using namespace std;
class Cstack
{
int *top;
int *bottom;
public:
Cstack()
{ top = bottom = new int[100]; }
void Push(int c)
{
if ((top - bottom) < 100)
*top ++=c;
}
int Pop()
{
if(--top >= bottom)
return *top;
}
~Cstack()
{ delete top;}
};
char * ReverseName(char *name)
{
Cstack s;
char *reverse;
for (int i=0; i<strlen(name); i++)
s.Push(name[i]);
reverse = new char[strlen(name) + 1];
for(int i = 0; i < strlen(name); i++)
reverse[i] = s.Pop();
reverse[strlen(name)] = '\0';
return reverse;
}
void main()
{
char str[20];
cout << "输入字符串: ";
cin >> str;
cout << "该字符串的反序为: "<<ReverseName(str)<<'\n';
system("pause");
}
运行:
- μC/OS之bulid stack
- c++STL之stack(堆栈)
- c++:stack
- C++ Stack Application - (Parenthesis Matching) 堆栈应用之"括号匹配"
- 【c++】调试技巧之调用堆栈 - Call stack
- C++(24):STL初步之stack、queue
- c++STL的stack的应用之括号匹配
- Stack-c++template
- c++:什么是stack frame?
- c++stack容器介绍
- [C++] Stack / queue / priority_queue
- c++stack,queue
- c++stack容器介绍
- Leetcode-Min Stack(C++)
- Stack链表C实现
- [C++]Stack with Template
- leetcode_155_Min Stack(C++)(easy)
- [C++]stack源码解析
- speak.vbs 调用TTS,说中文
- 网上有人关于协议和委托的理解
- oracle系统监控工具oswatch简介!
- bash 2>&1 重定向 顺序
- 线性探测哈希表的java代码
- C++之Stack
- spring3.0 MVC 配置全局日期转换
- C++ 内存池 -- C++ Memory Pool
- android--菜单
- CListCtrl使用技巧 (包括视图类(CListView)实现的CListCtrl同样适用,使用GetListCtrl()获取)
- Web开发中需要了解的东西
- Flex 超连接
- linux命令的简单总结(后续有补充)
- SESSION和客户端cookie的关系