顺序栈
2015-06-30 14:48
239 查看
//============================================================================
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
using namespace std;
#define MAXSIZE 100
struct Stack {
char data[MAXSIZE];
int pos;
};
void createStack(Stack* stack, char a[], int n) {
assert(n<MAXSIZE);
for (int i = 0; i < n; i++) {
stack->data[i] = a[i];
stack->pos = i;
}
}
void pop(Stack* stack) {
stack->data[stack->pos] = '\0';
stack->pos--;
}
void push(Stack* stack, char c) {
stack->data[stack->pos + 1] = c;
stack->pos++;
}
char getpopEle(Stack* stack)
{
return stack->data[stack->pos];
}
void ShowStack(Stack* stack) {
for (int i = 0; i < stack->pos + 1; i++) {
cout << stack->data[i];
}
}
int main() {
Stack stack;
char a[] = { 'a', 'b', 'c', 'd' };
createStack(&stack, a, strlen(a));
ShowStack(&stack);
pop(&stack);
push(&stack, 'e');
char e=getpopEle(&stack);
cout<<e<<endl;
ShowStack(&stack);
return 0;
}
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
using namespace std;
#define MAXSIZE 100
struct Stack {
char data[MAXSIZE];
int pos;
};
void createStack(Stack* stack, char a[], int n) {
assert(n<MAXSIZE);
for (int i = 0; i < n; i++) {
stack->data[i] = a[i];
stack->pos = i;
}
}
void pop(Stack* stack) {
stack->data[stack->pos] = '\0';
stack->pos--;
}
void push(Stack* stack, char c) {
stack->data[stack->pos + 1] = c;
stack->pos++;
}
char getpopEle(Stack* stack)
{
return stack->data[stack->pos];
}
void ShowStack(Stack* stack) {
for (int i = 0; i < stack->pos + 1; i++) {
cout << stack->data[i];
}
}
int main() {
Stack stack;
char a[] = { 'a', 'b', 'c', 'd' };
createStack(&stack, a, strlen(a));
ShowStack(&stack);
pop(&stack);
push(&stack, 'e');
char e=getpopEle(&stack);
cout<<e<<endl;
ShowStack(&stack);
return 0;
}
相关文章推荐
- JNI--java和C++互相调用
- 算法---和为定值
- C++ map的基本操作和用法
- Crashlytcis - 闪退分析平台
- Effective C++ 条款28
- 理解char * 和 char [ ] 的区别 (重要)
- GET方法后 获取url 后面指定的 参数的 值
- 快速搭建Tiny开发项目
- android开发过程中自定义动画加载进度条实现过程
- Ubuntu14.04 关闭图形启动界面,启动文本界面
- 11gR2 集群(CRS/GRID)新功能—— SCAN(Single Client Access Name)
- 【ZOJ 3856】Goldbach(FFT)
- 安卓客户端测试中,那些容易忽略却又非常重要的测试内容
- java中FileOutputStream流,向文件中追加内容,而不是覆盖掉文件中原有的数据
- 使用TinySpider实战抓取自己博客中的内容
- bzoj1562
- You can get fifa 15 coins for your game.
- Nginx反向代理和负载均衡部署指南
- 【漂亮!!】DMA深度剖析
- Tiny实例:TINY框架官网制作过程详解