I tried to implement by myself a single linked list. For now, I only wrote an addition of an element to the end of the list, and a function which prints lists content. But when I want to print out a list my program gives me a segmentation fault. Heres my code:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class Stuff;
class List
{
    private :
        Stuff *first, *last;
    public :
        List();
        void addfront(Stuff *s);
        void print();
        ~List();
};
class Stuff
{
    private :
        string name;
        double price;
    public :
        Stuff();
        Stuff(string, double);
        void print();
        Stuff *next;
};
Stuff::Stuff()
{
    name = "";
    price = 0;
    next = NULL;
}
Stuff::Stuff(string n, double p)
{
    name = n;
    price = p;
}
void Stuff::print()
{
    cout << name << " " << price << "\n";
}
List::~List()
{
}
void List::addfront(Stuff *s)
{
    if(first == NULL )
       first = s;
   last->next = s;
   s->next = NULL;
   last = s;
}
void List::print()
{
    Stuff *p;
    if(last == first == NULL)
        cout << "list is empty!\n";
    else
        for (p = first; p != NULL; p = p->next)
            p->print();
}
List::List()
{
    first = last = NULL;
}
int main(int argc, char **argv)
{
    List l;
    Stuff *s1 = new Stuff("Coffe", 4.50);
    Stuff *s2 = new Stuff("Apple", 2.50);
    l.addfront(s1);
    l.addfront(s2);
    l.print();
    return 0;
}
 
     
     
     
    