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; }
|