Guest User

Untitled

a guest
Dec 9th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. template<typename Tip>
  7. class Niz{
  8. vector<Tip> v;
  9. int *trenutni;
  10.  
  11.  
  12. public:
  13. Niz() {
  14. v=new vector<Tip> ;
  15. }
  16.  
  17. int brojElemenata() const {
  18. return v.size();
  19. }
  20.  
  21. Tip trenutni() const;
  22.  
  23. bool prethodni();
  24.  
  25. bool sljedeci();
  26.  
  27. void pocetak() { trenutni=0; }
  28.  
  29. void kraj() { trenutni =v.size(); }
  30.  
  31. void dodajIspred(Tip element);
  32.  
  33. void dodajIza(Tip element);
  34.  
  35. void obrisi();
  36.  
  37. Tip operator[] (int n) const;
  38. }
  39.  
  40. Tip Niz::trenutni() const {
  41. if(v.size()==0) throw "Niz je prazan.";
  42. return v[trenutni];
  43. }
  44.  
  45. bool Niz::prethodni()
  46. {
  47. if(trenutni==0) return false;
  48. trenutni--;
  49. return true;
  50. }
  51.  
  52. bool Niz::sljedeci()
  53. {
  54. if(trenutni==v.size()) return false;
  55. trenutni++;
  56. return true;
  57. }
  58.  
  59. /* ove dvije nisu tacne, ako ih uradis proslijedi!
  60. void Niz::dodajIspred(Tip element) {
  61. if(v.size()==0) {
  62. v[0]=element;
  63. trenutni=0;
  64. }
  65. v.push_back();
  66. for (int i=trenutni; i<v.size(); i++)
  67. {
  68. for(int j=trenutni+1; j<v.size(); j++)
  69. {
  70. v[j]=v[i];
  71. }
  72. }
  73. v[trenutni]=element;
  74. }
  75.  
  76. void Niz::dodajIza(Tip element) {
  77. if(v.size()==0) {
  78. v[0]=element;
  79. trenutni=0;
  80. }
  81. v.push_back();
  82. for (int i=trenutni; i<v.size(); i++)
  83. {
  84. for(int j=trenutni+1; j<v.size(); j++)
  85. {
  86. v[j]=v[i];
  87. }
  88. }
  89. v[trenutni]=element;
  90. }
  91. */
  92. void Niz::obrisi() {
  93. if(v.size()==0) throw "Niz je prazan.";
  94. delete v[trenutni];
  95. if(trenutni==0) trenutni++;
  96. else trenutni--;
  97. }
  98.  
  99. Tip Niz::operator [](int n) const {
  100. if(n<0 || n>=v.size()) throw "Ne postoji taj clan niza.";
  101. return v[n];
  102. }
  103.  
  104.  
  105.  
  106. int main()
  107. {
  108. cout << "Hello world!" << endl;
  109. return 0;
  110. }
Add Comment
Please, Sign In to add comment