Sicily 2286. Stack Implementation
来源:互联网 发布:网络老虎机熊猫机器 编辑:程序博客网 时间:2024/06/07 13:19
2286. 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<int> MyStack;
Hint
Submit your implementations only.
Problem Source
ADTs: Implementations and Applications
// Problem#: 2286// Submission#: 3279937// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen Universitytypedef int Stack_entry;class Stack {public: Stack_entry s[10000]; int pos; Stack() { pos = 0; } bool empty() const { return pos == 0; } int size() const { return pos; } void push(const Stack_entry &item) { s[pos++] = item; } void pop() { if (pos == 0) return; pos--; } Stack_entry top() const { if (pos == 0) return -1; return s[pos - 1]; } ~Stack() {} Stack(const Stack & original) { *this = original; } void operator = (const Stack & original) { for (int i = 0; i < original.pos; i++) { s[i] = original.s[i]; } pos = original.pos; }};typedef Stack MyStack;
- Sicily 2286. Stack Implementation
- Sicily 2252. List Implementation
- Sicily 2250. Vector Implementation
- Stack Implementation in C++
- C++ Stack Implementation Discussion
- Sicily 1206 Stack Cylinders
- Sicily 7967. Book Stack
- Sicily 2302. Queue Implementation Using a Circular
- Implementation of queue with 2 stack
- C program for stack with array implementation
- Stack ---- Implementation in C and Python
- Reverse linked list using stack and stack's implementation
- (2011.07.20) 链式栈 // Link list-based stack implementation
- The Stack Is An Implementation Detail, Part One
- The Stack Is An Implementation Detail, Part Two
- Implementation
- implementation
- sicily 使用deque实现stack && 使用list实现queue
- VS2005 VS2010数据断点不能设置的原因 new data breakpoint is disabled
- va_list
- Largest Number
- 苹果键盘及Xcode快捷键整理
- 设计模式之适配器模式
- Sicily 2286. Stack Implementation
- 11个强大的Visual Studio调试小技巧
- 开源 java CMS - FreeCMS2.3 职位管理
- Sicily 2287. Expression Equivalence (optional)
- Android 基于google Zxing实现二维码、条形码扫描,仿微信二维码扫描效果
- Java多线程
- Sicily 1149. 等价表达式
- 认识编程语言(c++)
- Sicily 1923. Is It Nim?