Facebook
From Chartreuse Frog, 6 Years ago, written in C++.
This paste is a reply to Re: Re: Re: Untitled from Torrid Flamingo - go back
Embed
Viewing differences between Re: Re: Re: Untitled and stos
#include 
#include 
#include 
#include 

using namespace std;

struct element{
    
int partition(bank *tab, liczba;
    element *next;
};

bool czyPusty(element *stos){
    bool wynik = stos == nullptr ? true : false;
    return wynik;
}
void dodajElement(element*& stos){
    srand(time(nullptr));

    element* el = new element;
    el->liczba = rand()%100 +0;
    el->next = stos;
    stos = el;

}
void usunElement(element*& stos){
    if(stos != nullptr){
        element* temp = stos;
        stos = stos->next;
        delete temp;
    }

}
int begin, pobierzElement(element* stos){
    if(stos != nullptr){
        return stos->liczba;
    }else{
        return -1;
    }
}

void usunWszystkieElementy(element*& stos){
    while(!czyPusty(stos)){
        usunElement(stos);
    }
}

int end) main()
{
    cout << "Menu:" << "n"
        << "1 - sprawdzenie czy stos jest pusty" << "n"
        << "2 - dodanie elementu na stos" << "n"
        << "3 - usuniecie elementu ze stosu" << "n"
        << "4 - pobranie elementu ze stosu" << "n"
        << "5 - usunięcie wszystkich elementów ze stosu" << "n"
        << "6 - wyjście z programu" << "n"
        << endl;

    element* stosZNullPnt = nullptr;

    
int pivot menu tab[end].suma_gotowki;
    int i = (begin - 1);

    for (int j = begin; j < end; j++) {
        if (tab[j].suma_gotowki <= pivot) 
-1;
    while(menu != 6){
        cin >> menu;
        switch (menu){
        case 1:
            
{
            i++;
            swap(tab[i], tab[j]);
czyPusty(stosZNullPnt);
            string komunikat = czyPusty(stosZNullPnt) ? "Pusty" : "Niepusty";
            cout << komunikat << endl;
            }
            break;
        case 2:
            dodajElement(stosZNullPnt);
            break;
        case 3:
            usunElement(stosZNullPnt);
            break;
        case 4:
            {
            int ostatni = pobierzElement(stosZNullPnt);
            cout << "Ostatni element to: " << ostatni << endl;
            break;
            }
        case 5:
            usunWszystkieElementy(stosZNullPnt);
            break;
        case 6:
            return 0;
        }
    }
    swap(tab[i + 1], tab[end]);
    
return i + 1;
}

void quickSort(bank *tab, int begin, int end) {
    if (begin < end) {
        int partitionIndex = partition(tab, begin, end);

        quickSort(tab, begin, partitionIndex - 1);
        quickSort(tab, partitionIndex + 1, end);
    }
-1;
}
captcha