链栈
2015-06-30 16:10
288 查看
//============================================================================
// 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;
Stack* next;
};
Stack* pop(Stack* top) {
assert(top!=NULL);
Stack* stack = top;
top = top->next;
delete stack;
return top;
}
Stack* push(Stack* top, char c) {
Stack* stack = new Stack;
stack->data = c;
stack->next = top;
top = stack;
return top;
}
char getpopEle(Stack* top) {
return top->data;
}
void ShowStack(Stack* top) {
Stack* p = top;
while (p != NULL) {
cout << p->data;
p = p->next;
}
}
int main() {
Stack* top = NULL;
char a[] = { 'a', 'b', 'c', 'd' };
for (int i = 0; i < 4; i++) {
top = push(top, a[i]);
}
top = pop(top);
ShowStack(top);
cout<<getpopEle(top);
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;
Stack* next;
};
Stack* pop(Stack* top) {
assert(top!=NULL);
Stack* stack = top;
top = top->next;
delete stack;
return top;
}
Stack* push(Stack* top, char c) {
Stack* stack = new Stack;
stack->data = c;
stack->next = top;
top = stack;
return top;
}
char getpopEle(Stack* top) {
return top->data;
}
void ShowStack(Stack* top) {
Stack* p = top;
while (p != NULL) {
cout << p->data;
p = p->next;
}
}
int main() {
Stack* top = NULL;
char a[] = { 'a', 'b', 'c', 'd' };
for (int i = 0; i < 4; i++) {
top = push(top, a[i]);
}
top = pop(top);
ShowStack(top);
cout<<getpopEle(top);
return 0;
}
相关文章推荐
- 【Android】实现下载网络图片并保存到SD卡中
- CocoaPods进阶
- iOS开发拓展篇—音频处理(音乐播放器3)
- 对话框类的数据交换和检验
- JavaWeb学习记录(二)——防盗链技术
- JavaWeb学习记录(五)——Servlet随机产生验证码
- JSONObject与JSONArray的使用
- CListCtrl控件中显示进度条
- cstring 转 cstringarray 转 BYTE
- 黑马程序员 网络编程
- CocoaPods使用
- Mysql 子查询<二>这个面试题。。。。
- poj3260 The Fewest Coins
- 消除“Permission is only granted to system apps”错误
- mysql之数据库连接的方法封装及防sql注入
- kafka与传统的消息中间件对比
- sql 随笔 2015-06-30
- 选择器$("parent > child")、$("A B")、$("div#test")、$("div,#test")、$(".test","div")
- Linux定时修改MySQL慢查询日志文件名
- 正则表达式一