我的STL之旅 MyStack
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; /*
push(int item)
int pop()
top() 返回stact中的下一个元素
s.top()=12;
设置顶层元素
返回对其引用
*/
const int N=;
const int AN=;
int size;//记录大小
int *stack;//存储数据
int top;//记录顶端元素 void push(int item)
{
if(top==size){
int *a=new int[size+AN];
for(int i=;i<size;i++){
a[i]=stack[i];
}
stack=a;
}
stack[top++]=item;
} int pop()
{
if(top>)
return stack[--top];
} int &ttop()
{
if(top==size){
int *a=new int[size+AN];
for(int i=;i<size;i++){
a[i]=stack[i];
}
stack=a;
}
return stack[top++];
} int main()
{
top=;
stack=new int[N];
size=N;
for(int i=;i<*N;i++)
{
push(i);
}
cout<<"top: "<<top<<endl;
cout<<"pop() "<<pop()<<endl;
ttop()=;
for(int i=;i<top;i++){
cout<<stack[i]<<" ";
}
return ;
}
我的STL之旅 MyStack的更多相关文章
- 我的STL之旅 MyList
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> // ...
- 数据结构(DataStructure)与算法(Algorithm)、STL应用
catalogue . 引论 . 数据结构的概念 . 逻辑结构实例 2.1 堆栈 2.2 队列 2.3 树形结构 二叉树 . 物理结构实例 3.1 链表 单向线性链表 单向循环链表 双向线性链表 双向 ...
- C++ Standard Template Library STL(undone)
目录 . C++标准模版库(Standard Template Library STL) . C++ STL容器 . C++ STL 顺序性容器 . C++ STL 关联式容器 . C++ STL 容 ...
- C++ 标准模板库(STL)
C++ 标准模板库(STL)C++ STL (Standard Template Library标准模板库) 是通用类模板和算法的集合,它提供给程序员一些标准的数据结构的实现如 queues(队列), ...
- 【C++探索之旅】开宗明义+第一部分第一课:什么是C++?
内容简介 1.课程大纲 2.第一部分第一课:什么是C++? 3.第一部分第二课预告:C++编程的必要软件 开宗明义 亲爱的读者,您是否对C++感兴趣,但是C++看起来很难,或者别人对你说C++挺难的, ...
- 洛谷 P1078 文化之旅
P1078 文化之旅 题目描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不同的国家可能 ...
- C++ STL stack 用法
Stack(栈)是一种后进先出的数据结构,也就是LIFO(last in first out) ,最后加入栈的元素将最先被取出来,在栈的同一端进行数据的插入与取出,这一段叫做“栈顶”. 使用STL的s ...
- STL详解
STL概貌 ...
- <泛> STL - stack 模拟实现
今天,看C++Template的时候看到那人写了一个Stack,于是乎,手痒,自己也写了一个,在拜读了STD文件和C++模板元编程某些小节之后,你们就看到了这篇代码. 经过上述一番经历之后,我重新写了 ...
随机推荐
- c语言期末复习题
代码参考:<K&R> 1.单词计数 #include<stdio.h> #define IN 1 #define OUT 0 main() { int c, state ...
- Java 序列化 反序列化 历史版本处理
直接引用 http://www.cnblogs.com/xdp-gacl/p/3777987.html
- The import javax.servlet.http.HttpServletRequest cannot be resolved
Error: The import javax.servlet cannot be resolved The import javax.servlet.http.HttpServletRequest ...
- BitMap存储jpg到手机sd卡中
/** * 将BitMap转成Jpeg图片保存到sdcard(便于以后debug调试查看和裁切调试) */ private void saveBitmap(Bitmap bitmap, String ...
- Android基础:Activity
Activity基本概念 Activity代表活动窗口,通过Context加载页面显示内容,每一个Activity都必须在manifest.xml中注册. 一个应用程序由多个界面构成,回退栈,活动窗口 ...
- Construct Binary Tree from Preorder and Inorder Traversal [LeetCode]
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- MVC——入门+简单的小实例
MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controler)的缩写,一种软件设计典范,用于组织代码用一种业务逻辑和数据显示分离的方法. ...
- 0506--Scrum项目1.0
应用NABCD模型,分析你们初步选定的项目,充分说明你们选题的理由. 录制为演说视频,上传到视频网站,并把链接发到团队博客上. 团队项目选题 四则运算 NABCD 模型 1) N (Need 需求) ...
- 超实用的JavaScript技巧及最佳实践
众所周知,JavaScript是一门非常流行的编程语言,开发者用它不仅可以开发出炫丽的Web程序,还可以用它来开发一些移动应用程序(如PhoneGap或Appcelerator),它还有一些服务端实现 ...
- Shannon entropy
Shannon entropy is one of the most important metrics in information theory. Entropy measures the unc ...