Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #pragma once
  2. #include <iostream>
  3. #include "Cvor.h"
  4. using namespace std;
  5. template <class Tip>
  6. struct ListaPov
  7. {
  8. Cvor<Tip> * prviCvor = nullptr;
  9.  
  10. void DodajNaKraj(Tip x)
  11. {
  12. Cvor<Tip>* t = prviCvor;
  13. if (t == nullptr)
  14. {
  15. prviCvor = new Cvor<Tip>(x, nullptr);
  16. return;
  17. }
  18.  
  19. while (t->next != nullptr)
  20. {
  21. t = t->next;
  22. }
  23. t->next = new Cvor<Tip>(x, nullptr);
  24. }
  25. void DodajNaPocetak(Tip x)
  26. {
  27. Cvor<Tip> *t = new Cvor<Tip>(x, prviCvor);
  28. prviCvor = t;
  29.  
  30.  
  31. }
  32. Tip UkloniSaKraja()
  33. {
  34. if (JeLiPrazna())
  35. {
  36. cout << "Greska" << endl;
  37. return 0;
  38. }
  39. Cvor<Tip> * t = prviCvor;
  40. Cvor *b = nullptr;
  41. while (t->next != nullptr)
  42. {
  43. b = t;
  44. t = t->next;
  45. }
  46. Tip rezultat = t->info;
  47. delete t;
  48. if (b != nullptr)
  49. b->next = nullptr;
  50. else
  51. prviCvor = nullptr;
  52. return rezultat;
  53. }
  54. Tip UkloniSaPocetka()
  55. {
  56. if (JeLiPrazna())
  57. {
  58. cout << "Greska" << endl;
  59. return 0;
  60. }
  61. Cvor<Tip> *t = prviCvor;
  62. prviCvor = prviCvor->next;
  63. Tip x = t->info;
  64. delete t;
  65. return x;
  66.  
  67. }
  68. void Print()
  69. {
  70. Cvor<Tip> *t = prviCvor;
  71. while (t != nullptr)
  72. {
  73.  
  74. cout << t->info << endl;
  75. t = t->next;
  76. }
  77. }
  78. bool JeLiPrazna()
  79. {
  80. return prviCvor == nullptr;
  81.  
  82. }
  83. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement