Kashub's Code Barn - "wal_sie"

podświetlone jako oracle8 (dodał(a) Damian @ 2011-10-15 15:59:54)

Twoja wyszukiwarka
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
#include <cstdlib>
#include <iostream>
#include <conio.h>
 
USING namespace std;
 
 
struct elem {
   int dane;
   elem *nast;             
};
 
void push(elem *&stos, int x);
int pop(elem *&stos);
int topEl(elem *stos);
bool isEmpty(elem *stos);
void usun(elem *&stos);
int COUNT(elem *stos);
 
int main(int argc, CHAR *argv[])
{
    unsigned int OPTION = 0;
    int liczba = 0;
    elem *stos = NULL;
 
 
    WHILE(OPTION!=7) {
 
 
 
       cout << "\n\n\n\n1. Polozenie elementu na wierzcholku stosu " << endl;      
       cout << "2. Pobranie ostatnio odlozonego elementu i zwrocenie go jako wartosci funkcji " << endl;
       cout << "3. Zwrocenie elementu znajdujacego sie na wierzcholku stosu bez jego usuwania " << endl;
       cout << "4. Sprawdzenie czy stos jest pusty " << endl;    
       cout << "5. Usun stos " << endl; 
       cout << "6. Zlicz elementy na stosie " << endl; 
       cout << "7. Koniec programu " << endl;
       cout << "\n\n\nWybierz opcje " << endl;
       cin >> OPTION;
 
       switch (OPTION) {
              CASE 1: cout << "Podaj dowolna liczbe" << endl;
                      cin >> liczba;
                      push(stos, liczba);
                      cout << "Polozono element na wierzcholek stosu" << endl;
                      break;
              CASE 2: 
                      cout << "Pobrany element ze szczytu stosu " << pop(stos) << endl;
                      break;
              CASE 3: 
                      cout << "Pobrany element z wierzcholku stosu bez usuwania " << topEl(stos) << endl;
                      break;
              CASE 4: 
                      IF (isEmpty(stos)) 
                         cout << "stos jest pusty" << endl;
                      ELSE
                          cout << " stos nie jest pusty" << endl; 
                      break;
              CASE 5: usun(stos);
                      cout << "Usunieto caly stos" << endl;
                      break;
              CASE 6: cout << "Ilosc elementow w stosie: " << COUNT(stos) << endl;
                      break;
       }
 
    }
    RETURN 0;
}
 
 
//================================================
void push(elem *&stos, int x) {
 
     elem *e = NEW elem;
     e->dane = x;
     e->nast = stos;
 
     stos = e;
}
//================================================
 
int pop(elem *&stos) {
 
    elem *e;
 
    IF (stos == NULL) {
       cout <<"pusty stos" << endl;
       RETURN -121;
    }
 
    int zwr = stos->dane;
 
    e = stos->nast;
    DELETE stos;
    stos = e;
 
    RETURN zwr;
}
 
//================================================
 
int topEl(elem *stos) {
 
     IF (stos == NULL) {
       cout <<"pusty stos" << endl;
       RETURN -121;
     }
 
     int zwr = stos->dane;
     RETURN zwr;
}
 
//================================================
 
bool isEmpty(elem *stos) {
     IF (stos == NULL) {
       RETURN TRUE;
     }
     ELSE
       RETURN FALSE;
}
 
//================================================
 
void usun(elem *&stos) {
 
 
    elem *e;
 
    WHILE(stos) {
        e = stos->nast;
        DELETE stos;
        stos = e;
    }
}
 
//================================================
 
int COUNT(elem *stos) {
 
    IF (stos == NULL)
       RETURN 0;
 
    int il = 0;    
 
    WHILE(stos) {
        stos = stos->nast;
        ++il;
    }
 
    RETURN il;
}
 
| Opony zimowe | | Kamery IP sklep | | karma dla psa - sklep | | Programista Trójmiasto | | Blog o książkach | | Gdzie przenieść blog za darmo? | | Gnieżdżewo | | Opisy GG |