Advertisement
Guest User

dupabobra

a guest
Oct 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. // Zadanie 1 lista.cpp : Ten plik zawiera funkcję „main”. W nim rozpoczyna się i kończy wykonywanie programu.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8. class Obiekt
  9. {
  10.     private:
  11.     int numer;
  12.     char nazwa;
  13. };
  14.  
  15.     template <typename T>
  16.     class przejscie
  17.     {
  18.     public:
  19.             T dane;
  20.             przejscie*dalej;
  21.             przejscie*wstecz;
  22.             przejscie(T dane)
  23.     {
  24.         this->dane = dane;
  25.     }
  26.  
  27.     };
  28.  
  29. template <typename T>
  30. class Lista
  31. {
  32.  
  33.  
  34.     public:
  35.  
  36.     przejscie<T>*glowa = NULL;
  37.     przejscie<T>*ogon = NULL;
  38.     int dlugosc;
  39.  
  40.    
  41.     void dodaj_na_poczatek(T dane)//? nie jestem pewny
  42.     {
  43.         przejscie<T>*wezel = new przejscie<T>(dane);
  44.  
  45.         if (dlugosc > 0)
  46.  
  47.         {
  48.             glowa->wstecz = wezel;
  49.             wezel->dalej = glowa;
  50.             glowa = wezel;
  51.         }
  52.         else
  53.         {
  54.             glowa = wezel;
  55.             ogon = wezel;
  56.         }
  57.  
  58.         dlugosc++;
  59.     }
  60.  
  61.     void dodaj_na_koniec (T dane)
  62.     {
  63.         przejscie<T>*wezel = new przejscie<T>(dane);
  64.  
  65.         if (dlugosc > 0)
  66.         {
  67.             ogon -> dalej = wezel;
  68.             wezel -> wstecz = ogon;
  69.             ogon = wezel;
  70.         }
  71.         else
  72.         {
  73.             glowa = wezel;
  74.             ogon = wezel;
  75.         }
  76.         dlugosc++;
  77.     }
  78.  
  79.     void usun_k()
  80.     {
  81.         przejscie<T>*wezel = ogon->wstecz;
  82.         delete ogon;
  83.         ogon = wezel;
  84.         wezel->dalej = NULL;
  85.         dlugosc--;
  86.     }
  87.  
  88.     void usun_p()
  89.     {
  90.         przejscie<T>*wezel = glowa->dalej;
  91.         delete glowa;
  92.         glowa=wezel;
  93.         wezel -> wstecz = NULL;
  94.         dlugosc--; 
  95.     }
  96.    
  97.     void zwroc_dane(int i)
  98.     {
  99.         przejscie<T>*tym = glowa;
  100.         int j = 0;
  101.         for (j = 0; j < i; j++)
  102.         tym = tym->dalej;
  103.        
  104.     }
  105.     void podmiana(int i, T dane)
  106.     {
  107.         przejscie<T>*index = glowa;
  108.         int g = 0;
  109.         for (g = 0; g < i; g++)
  110.         index = index->dalej;
  111.         index->dane = dane;
  112.     }
  113.     T znajdz_element(T dane)
  114.     {
  115.         przejscie<T>*li = glowa;
  116.        
  117.        
  118.  
  119.     }
  120.     void znajdz_usun(T dane)
  121.     {
  122.  
  123.     }
  124.    
  125.    
  126. };
  127.  
  128. int main()
  129. {
  130.     std::cout << "Witaj \n";
  131.  
  132.     Lista<int>* listy = new Lista<int>();
  133.  
  134.     listy->dodaj_na_poczatek(1);
  135.     listy->dodaj_na_poczatek(3);
  136.     listy->dodaj_na_poczatek(6);
  137.  
  138.     listy->dodaj_na_koniec(2);
  139.     listy->dodaj_na_koniec(5);
  140.     listy->dodaj_na_koniec(6);
  141.    
  142.     //listy->usun_k();
  143.    
  144.     //listy->usun_p();
  145.    
  146.     //listy->zwroc_dane(0);
  147.    
  148.     //listy->podmiana(2, 3);
  149.    
  150.    
  151.     przejscie<int>* temp = listy->glowa;
  152.     while (temp != NULL)
  153.     {
  154.         std::cout <<"element listy: " << temp->dane << std::endl;
  155.         temp = temp->dalej;
  156.     }
  157.     delete listy;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement