#include <stdio.h>
#include "bottle3.h"


bottle *bottle::top = NULL;


bottle::bottle(int n)
{
    index = n;

    // link it into the master list
    next = top;
    top = this;
}


bottle::~bottle()
{
    // unlink
    bottle **it;
    // find
    for (it = &top; *it && *it != this; it = &(*it)->next)
        ;
    // change links
    if (*it)
        *it = (*it)->next;
}


void bottle::sing()
{
    printf("%d bottles of beer on the wall\n", index);
}


bottle *bottle::pop()
{
    printf("If one of those bottles should happen to fall,\n");
    return top;
}
