Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /*Folosim macro pentru a putea modifica mai usor marimea stivei in program*/
- #define LIM 10
- /*Verificare daca stiva este vida sau nevida*/
- bool isEmpty(int top) {
- if (top == 0)
- return true;
- return false;
- }
- /*Functia pentru inserare elemente in stiva*/
- void push(int stiva[], int& top, int numar) {
- stiva[top] = numar;
- top = top + 1;
- }
- /*Returneaza elementul de pe pozitia top (ultimul element)*/
- int peekTop(int stiva[], int top) {
- return stiva[top];
- }
- /*Functia care elimina utltimul element*/
- void pop(int stiva[], int& top) {
- int rezultat = peekTop(stiva, top);
- top = top - 1;
- }
- /*Returneaza marimea stivei*/
- int size(int top) {
- return top;
- }
- void afisare(int stiva[], int& top)
- {
- for (int i = 0; i < top; i++)
- cout << stiva[i] << " ";
- cout << endl;
- }
- int main()
- {
- /*Declarare variabile (stiva statica & top)*/
- int stiva[LIM], top = 0;
- push(stiva, top, 2);
- push(stiva, top, 4);
- push(stiva, top, 6);
- push(stiva, top, 7);
- push(stiva, top, 8);
- cout << "Afisare stiva: " << endl;
- afisare(stiva, top);
- pop(stiva, top);
- pop(stiva, top);
- pop(stiva, top);
- cout << endl;
- cout << "Afisare stiva: " << endl;
- afisare(stiva, top);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment