jeudi 29 septembre 2016

Using decorator design pattern to create a doubly linked list by decorating a singly linked list

I am quite a newbie when it comes to design patterns so am having a hard time grasping the concept of the decorator design pattern. Is it possible to decorate a singly linked list class to a doubly linked list class which inherits from it? I would like to decorate the following class:

ListAsSLL.h:

#ifndef LISTASSLL_H
#define LISTASSLL_H

class ListAsSLL
{
protected:
    struct node{
        int i;
        struct node* next;
    };
    node* head;
    node* tail;
    int listSize;

public:
    ListAsSLL();
    virtual void addToBeginning(int obj);
    virtual void addAtPos(int obj, int i);
    virtual void addToEnd(int obj);
    virtual void del(int i);
    virtual void overwrite(int obj, int i);
    virtual void grow();
    virtual void shrink();
};

#endif //LISTASSLL_H

Giving the doubly linked list class the same functionality with the added feature of having a struct with a pointer to the previous node.

Hopefully someone can shed some light on how to do this. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire