#1 2011-10-19 21:16:21

michal8m

Administrator

Zarejestrowany: 2011-02-03
Posty: 45
Punktów :   

Stos zad 6

Zaimplementuj stos z uzyciem typu tablicowego (statycznego).







#include <iostream>
#include <cstdlib>

using namespace std;

struct stos {
    int tab[5];
    int rozmiar;
}
;

void push(stos* &s, int x) {
    if (s == NULL) {
        s = new stos;
        s->rozmiar = -1;
    }
    if (s->rozmiar == (sizeof (s->tab) / sizeof (int)) - 1) {
        cout << "Pelny" << endl;
    } else {
        s->rozmiar++;
        s->tab[s->rozmiar] = x;
    }
}

int pop(stos* &s) {
    int w = 0;
    if (s != NULL) {
        if (s->rozmiar == -1) {
            cout << "Pusty" << endl;
        } else {
            w = s->tab[s->rozmiar];
            s->rozmiar--;
        }
    } else {
        cout << "Pusty" << endl;
    }
    return w;
}

int topEl(stos *s) {
    return s->tab[s->rozmiar];
}

bool isEmpty(stos *s) {
    if (s == NULL) {
        return 1;
    }
    return s->rozmiar == -1;
}

void usun(stos *&s) {
    delete s->tab;
    s->rozmiar = -1;
}

int count(stos *s) {
    return s->rozmiar + 1;
}

int main() {
    stos* e = NULL;

    system("Pause");
    return 0;
}

Offline

 

Stopka forum

RSS
Powered by PunBB
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi


Darmowe Forum | Ciekawe Fora | Darmowe Fora
www.javaity.pun.pl wellness ciechocinek cennik