#1 2011-10-12 17:33:55

michal8m

Administrator

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

Stos zad1

Zaimplementuj podstawowe operacje stosowe:









#include <iostream>
#include <cstdlib>

using namespace std;

struct elem {
    int dane;
    elem *nast;
};

void push(elem *&stos, int x) {
    elem* e = new elem;
    e->dane = x;
    e->nast = stos;
    stos = e;
}

int pop(elem *&stos) {
    int w = stos->dane;
    elem* d = stos;
    stos = stos->nast;
    delete d;
    return w;
}

int topEl(elem* stos) {
    return stos->dane;
}

int count(elem* stos) {
    int iloscEl = 0;
    while (stos != NULL) {
        iloscEl++;
        stos = stos->nast;
    }
    return iloscEl;
}

bool isEmpty(elem* stos) {
    bool w = true;
    if (count(stos) > 0) {
        w = false;
    }
    return w;
}

void usun(elem* &stos) {
    while (stos != NULL) {
        pop(stos);
    }
}

int main() {
    elem* pierwszy = 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
ehotelsreviews.com Hotels MarvĂŁo weekend w ciechocinku z zabiegami