西西里2286. Stack Implementation

本文详细介绍了如何使用C++实现标准栈结构。包括构造、销毁、压栈、弹栈、判断栈是否为空、获取栈大小及访问栈顶元素等核心功能。并探讨了安全特性如拷贝构造函数和赋值运算符的实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这么过分一定要发优快云!

题目

  1. Stack Implementation
    Constraints
    Time Limit: 1 secs, Memory Limit: 256 MB , Framework Judge

Description
Implement the following Stack:

typedef int Stack_entry;

class Stack {
public:
// Standard Stack methods
Stack();
bool empty() const;
/* Returns true if the stack is empty, otherwise, returns false.
/
int size() const;
/
Returns the number of elements in the stack.
*/
void push(const Stack_entry &item);
/*item is pushed into the stack and it becomes the new top element.
*/
void pop();
/*The top item is removed if the stack is not empty.
Otherwise, nothing happens.
*/

Stack_entry & top() const;
/* The top element is returned by item if the stack is not empty,
and the stack remains unchanged.
Nothing happens if the stack is empty.
*/
// Safety features
~Stack();
Stack(const Stack &original);
void operator =(const Stack &original);
};

typedef Stack MyStack;

//or if your are using templates

typedef Stack MyStack;

Hint
Submit your implementations only.

Problem Source
ADTs: Implementations and Applications

AC的答案

这题目其实是很基础的stack的实现,不过这个题目的要求怎么跟STL的一毛一样?这不是诱惑我吗?
(/≧▽≦)/
什么都不说了,晒图了
AC

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值