Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
using namespace std; class Array { private: int kapacitet; int n; int * niza; public: Array() { kapacitet = 5; niza = new int[kapacitet]; n = 0; } Array(int _kapacitet) { kapacitet = _kapacitet; niza = new int[kapacitet]; n = 0; } Array & operator += (int x) { int tmp_niza[n + 1]; for(int i = 0; i < n; i++) { tmp_niza[i] = niza[i]; } tmp_niza[n] = x; n++; if(n > kapacitet) { kapacitet *= 2; } niza = new int[kapacitet]; for(int i = 0; i < n; i++) { niza[i] = tmp_niza[i]; } return *this; } Array & operator -= (int x) { int tmp_niza[n]; int j = 0; for(int i = 0; i < n; i++) { if(niza[i] != x) { tmp_niza[j] = niza[i]; j++; } } n = j; niza = new int[kapacitet]; for(int i = 0; i < n; i++) { niza[i] = tmp_niza[i]; } return *this; } bool operator == (Array tmp) { if(kapacitet == tmp.kapacitet and n == tmp.n) { bool ok = true; for(int i = 0; i < n; i++) { if(niza[i] != tmp.niza[i]) { ok = false; } } return ok; } else { return false; } } int & operator [] (int i) { return niza[i]; } friend ostream & operator << (ostream & stream, Array tmp); }; ostream & operator << (ostream & stream, Array tmp) { for(int i = 0; i < tmp.kapacitet; i++) { if(i < tmp.n) { stream << tmp.niza[i] << " "; } else { stream << " - "; } } stream << endl; return stream; } int main() { Array a; a += (6); a += (4); a += (3); a += (2); a += (1); Array b(a); b -= (2); b -= (3); a[0] = 9; //primena na operatorot [] cout << " a: " << a; cout << " b: " << b; if (a == b) cout << "Isti se"; else cout << "Ne se isti"; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)