Advertisement
frentzy

Ceva problema cu stiva ez

May 29th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. class Stiva {
  9. public:
  10.     virtual void push() {
  11.  
  12.     }
  13.     virtual void pop() {
  14.  
  15.     }
  16.     virtual void isEmpty() {
  17.  
  18.     }
  19. };
  20.  
  21. struct Lista {
  22.     //int nr = NULL;
  23.     Lista* next;
  24. };
  25.  
  26.  
  27.  
  28.  
  29. class StivaInlantuita : Stiva {
  30. private:
  31.     Lista * listStiva,*first,*last;
  32. public:
  33.     StivaInlantuita(int dimensiuneStiva) {
  34.         listStiva = new Lista[dimensiuneStiva];
  35.         first = listStiva;
  36.         last = listStiva;
  37.         last->next = NULL;
  38.         for (int i = 1; i < dimensiuneStiva; i++) {
  39.             Lista *tempLista = new Lista;
  40.             last->next = tempLista;
  41.             last = tempLista;
  42.             last->next = NULL;
  43.         }
  44.     }
  45.     void push() {
  46.         if (first != NULL) {
  47.             Lista *tempLista = new Lista;
  48.             last->next = tempLista;
  49.             last = tempLista;
  50.             last->next = NULL;
  51.         }
  52.         else if (first == NULL) {
  53.             listStiva = new Lista;
  54.             first = listStiva;
  55.             last = listStiva;
  56.             last->next = NULL;
  57.         }
  58.     }
  59.     void pop() {
  60.         if (first->next != NULL) {
  61.             Lista *tempLista = last;
  62.             Lista *passby;
  63.             for (passby = first; passby != last; passby = passby->next) {
  64.  
  65.             }
  66.            
  67.             last = passby;
  68.             last->next = NULL;
  69.             delete tempLista;
  70.             tempLista = NULL;
  71.         }
  72.         else {
  73.             delete first;
  74.  
  75.             first = NULL;
  76.         }
  77.     }
  78.     void isEmpty() {
  79.         if (first != NULL) {
  80.             cout << "Stiva nu este Vida\n";
  81.         }
  82.         else {
  83.             cout << "Stiva este Vida\n";
  84.         }
  85.     }
  86. };
  87.  
  88.  
  89. void main() {
  90.     StivaInlantuita test(1);
  91.     test.isEmpty();
  92.     test.pop();
  93.     test.isEmpty();
  94.     test.push();
  95.     test.isEmpty();
  96.  
  97.  
  98.  
  99.     _getch();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement