Implement a stack that pops out the mostfrequently added item. Stack supports 3 functions – push,

本文主要是介绍Implement a stack that pops out the mostfrequently added item. Stack supports 3 functions – push,,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、问题

Implement a stack that pops out the mostfrequently added item. Stack supports 3 functions – push, pop and top.Givecomplexity of each functions in your implementation


2、算法

实现有两种,一种使用标准库中的vector,另一种使用上节已经实现的List http://blog.csdn.net/u011476173/article/details/39025083


template <typename T>

class Stack{

private:

        //std::vector<T> stack ;

        List<T> stack ;


public:

        void push( const T& data )

        {

                //stack.push_back( data ) ;

                stack.insert( data ) ;

        }


        void pop()

        {

                //stack.pop_back() ;

                stack.remove( 0 ) ;

        }


        T& top()

        {

                //return stack.back() ;

                return stack.getHead()->content() ;

        }

}

这篇关于Implement a stack that pops out the mostfrequently added item. Stack supports 3 functions – push,的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1044805

相关文章

UnityException: Gizmo drawing functions can only be used in OnDrawGizmos and OnDrawGizmosSelected.

You don't have to call OnDrawGizmos() From anywhere, it is a editor function to display gizmos in the scene-view and is called automatically called!! 不能在任何地方调用 OnDrawGizmos(),这个函数是自动调用的。这个函数是编辑器函数,用来

listView的item向左滑动实现删除

有一种删除功能是这样的: ListView的item向左滑动,实现删除功能 注释很清楚,简单明了 1.自定义LeftDeleteView.java继承HorizontalScrollView.java public class LeftDeleteView extends HorizontalScrollView { private int start;//开始滑动的位

使用stack分析RAD-seq

一次简化基因组数据分析实战 尽管目前已经有大量物种基因组释放出来,但还是存在许多物种是没有参考基因组。使用基于酶切的二代测序技术,如RAD-seq,GBS,构建遗传图谱是研究无参考物种比较常用的方法。Stacks就是目前比较通用的分析流程,能用来构建遗传图谱,处理群体遗传学,构建进化发育树。 这篇教程主要介绍如何使用Stacks分析基于酶切的二代测序结果,比如说等RAD-seq,分析步骤为环境

使用不同数据类型实例化Stack泛型类的代码

package 泛型;import java.math.BigDecimal;import java.math.MathContext;public class StackDemoApp {public static void main(String[] args) {//长类型栈System.out.println("创建'Long'类型栈");//创建用于保存Long数据类型的Stack对象

C++ std::vector 的 emplace_back 能否完全取代 push_back

区别: push_back:先在调用处构造一次 class,传递进 push_back 内后再进行拷贝到缓冲区。 emplace_back:在内部直接将构造 class 的参数转发构造到缓冲区。   如果以上说法不好理解,那么用代码来表示。 // 该 Class 支持隐式构造class Class{public:Class(int a) : _a(a) {}int _a;};ve

git push VS git fetch

最近我们研发团队所有项目源码的版本管理实现了统一化,全部统一采用git进行管理,丢弃svn。在使用git的过程中,遇到了git pull和git fetch两个命令,针对具体含义与区别比较模糊,进而进行了学习与总结。 要想搞清楚git pull和git fetch的区别,我们需要弄明白git的架构,它是分布式的版本管理系统。 上图展示了git的整体架构,以及和各部分相关的主要命令。先说明下其中

【Rust每周一知】一种奇怪的表示 T::Item

我们都知道,Rust有一种叫 完全限定语法(fully-qualified syntax) 的东西。请看下面的例子: trait AAA {type Item;fn test();}struct Foo;impl AAA for Foo {type Item = String;fn test() {println!("a test.");}}fn main() {let f: Foo::It

Spring Boot启动报错Lombok supports: sun/apple javac 1.6, ECJ

版本 idea 2023.3.4 <dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.32</version></dependency> 解决方式 File->Settings->Build, Execution, Deployment->C

git push代码403

http://www.cnblogs.com/hanxiangduo/archive/2012/09/03/github.html 在申请完github账号,(申请及创建可以参考下面的资料链接)并创建好项目提交代码时出现了403的错误。 错误代码如下: error: The requested URL returned error: 403 while accessing https://g

微信小程序-获取swiper-item中image的值(item-id)

滑过一个图片获取该图片的id,或者打印其他的item值 只需要加:item-id="{{item.id}}" <swiper bindchange="swiperchange"><block wx:for="{{photos}}" wx:key='{{item.id}}'><swiper-item item-id="{{item.id}}"><image src='{{item.url}