Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Lista{
- public:
- typedef int pozycja;
- typedef int wartosc;
- private:
- wartosc*tab;
- unsigned int n,roz_tab;//liczba elementow i rozmiar tablicy
- public: Lista();
- ~Lista();
- bool empty();
- wartosc front();
- wartosc back();
- void push_front(wartosc);
- void push_back(wartosc);
- void pop_front();
- void pop_back();
- void insert(pozycja,wartosc);
- void erase(pozycja);
- pozycja first();
- pozycja last();
- pozycja next(pozycja);
- wartosc & at(pozycja);
- };
- int main()
- {
- cout << "Hello World!" << endl;
- return 0;
- }
- Lista::Lista() // konstruktor
- {
- n=0;
- roz_tab=100; //na początek stała wartość która ma nam wystarczyć (nie sugerować się tym)
- tab=new wartosc[roz_tab];
- }
- Lista::~Lista() // destruktor
- {
- delete [] tab; //usuwa tablice
- }
- bool Lista::empty(){
- if(n==0)
- return true; //pusty ( tak)
- else
- return false;// pusty(nie)
- }
- Lista::wartosc Lista::front(){
- return tab[0]; // zwraca pierwszy
- }
- Lista::wartosc Lista::back(){
- return tab [n-1]; // zwraca ostatni
- }
- void Lista::push_back(wartosc w)
- {
- tab[n]=w; // dodajemy na końcu element
- n++;
- }
- void Lista::push_front(wartosc w)
- {
- for (unsigned i=n;i>0;i--) {
- tab[i]=tab[i-1];
- tab[0]=w;
- n++;
- }
- }
- void Lista ::pop_back(){
- n--;
- }
- void Lista:: pop_front()
- {
- for(unsigned int i=0;i<n-1;i++)
- tab[i]=tab[i+1];
- n--;
- }
- void Lista::insert(pozycja p, wartosc w)
- {
- for(unsigned int i=n;i>p;i--)
- tab[i]=tab[i-1];
- tab[p]=w;
- n++;
- }
- //void Lista::push_front(wartosc w){ Alternatywa dla powyższego zapisu;
- // insert(0,w);
- //}
- //void Lista::push_back(wartosc w)
- //{
- // insert(n,w);
- //}
- void Lista::erase(pozycja p)
- {
- for(unsigned int i=p;i<n-1;i++)
- tab[i]=tab[i+1];
- n--;
- }
- //void Lista:: pop_front(wartosc w)
- //{
- // erase(0,w);
- //}
- //void Lista::pop_back(wartosc w)
- //{
- // erase(n-1,w);
- //}
- Lista::pozycja Lista::first(){
- return 0;
- }
- Lista::pozycja Lista::last(){
- return n-1;
- }
- Lista::pozycja Lista::next(pozycja p){
- return p+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement