Aufgabe 2

    Wir implementieren die rekursive Datenstruktur: LISTE:

  1. Implementieren Sie eine Klasse MyList, die wstrings in der Liste speichern kann. (Rekursive Datenstruktur)
    class MyList {
    private:
            std::wstring content;
            std::shared_ptr<MyList>  next_element;
    
    public:
            std::shared_ptr<MyList>  get_pointer_to_next_element();
            const std::wstring &get_content();
            void set_content(std::wstring);
            void set_pointer_to_next_element(const std::wstring &w);
            MyList(const std::wstring &w);
    };
    bool nil (std::shared_ptr<MyList> l);
    bool member (const std::wstring &w, std::shared_ptr<MyList> l);
    void print (std::shared_ptr<MyList> l);
    std::shared_ptr<MyList> append(const std::wstring &w, std::shared_ptr<MyList> l);
    
  2. Nun soll es folgende Funktionen geben: Wir erinnern uns an PROLOG:

  3. const std::wstring &head (std::shared_ptr l); liefert das erste Element der Liste l
  4. std::shared_ptr<MyList> tail (std::shared_ptr<MyList> l); entfernt das erste Element der Liste l und liefert die verkürzte Liste l zurück
  5. bool nil (std::shared_ptr<MyList> l); liefert true, wenn die Liste l leer ist
  6. Implementieren sie mit Hilfe der Funktionen head, tail und nil folgende Funktionen

  7. bool member (const std::wstring &w, std::shared_ptr<MyList> l); liefert true, wenn der wstring w in der Liste l vorkommt.
  8. void print (std::shared_ptr<MyList> l); druckt alle Elemente der Liste aus
  9. std::shared_ptr<MyList> append (const std::wstring &w, std::shared_ptr<MyList> l); fügt den wstring w am Ende der Liste an und liefert die Liste als Ergebnis zurück.

hier die .hpp Datei:

class MyList {
private:
std::wstring content;
std::shared_ptr<MyList> next_element;

public:
std::shared_ptr<MyList> get_pointer_to_next_element();
const std::wstring &get_content();
void set_content(std::wstring);
void set_pointer_to_next_element(const std::wstring &w);
MyList(const std::wstring &w);
};

const std::wstring &head (std::shared_ptr<MyList> l);
std::shared_ptr<MyList> tail (std::shared_ptr<MyList> l);
bool nil (std::shared_ptr<MyList> l);
bool member (const std::wstring &w, std::shared_ptr<MyList> l);
void print (std::shared_ptr<MyList> l);
std::shared_ptr<MyList> append(const std::wstring &w, std::shared_ptr<MyList> l);