Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Tray
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//g++ 7.4.0 #include <iostream> using namespace std; template <class T> class Tray{ private: int size; int top; T* data; public: Tray(int s=100) : size(s),top(-1){ data=new T[size];} ~Tray(){delete [] data;} void push(const T& x) {data[++top]=x;} T pop(){return data[top--];} int isEmpty() const {return top==-1;} int isFull() const { return top==size-1;} }; int main () { Tray<int> iTray1(5); Tray<int> iTray2(10); Tray<char> cTray(10); cTray.push('R'); cTray.push('A'); cTray.push('E'); cTray.push('Y'); iTray1.push(0); iTray1.push(2); iTray1.push(0); iTray1.push(2); cout<<cTray.pop()<<endl; cout<<cTray.pop()<<endl; cout<<cTray.pop()<<endl; cout<<cTray.pop()<<endl; cout<<endl; cout<<iTray1.pop()<<endl; cout<<iTray1.pop()<<endl; cout<<iTray1.pop()<<endl; cout<<iTray1.pop()<<endl; if(iTray1.isEmpty()) cout<<"iTray1 is empty."; else cout<<"iTray1 is not empty."; if(iTray2.isEmpty()) cout<<"\niTray2 is empty."; else cout<<"iTray2 is not empty."; if(cTray.isFull()) cout<<"\ncTray is full."; else cout<<"\ncTray is not full."; return 0; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.3 sec, absolute running time: 0.18 sec, cpu time: 0.01 sec, memory peak: 5 Mb, absolute service time: 1,64 sec
edit mode
|
history
|
discussion
Y E A R 2 0 2 0 iTray1 is empty. iTray2 is empty. cTray is not full.