/*
 * Sonny Rajagopalan
 * CISC181-040 (06J), Summer 2006
 *
 * Having fun with linked lists
 */
#include <iostream>
using namespace std;

class LList
{
  int key;
  LList* next;  
 public:
  LList();
  LList(int, LList*);
  void printTheList();
  void addToTheList(int);
  //void deleFromList(LList*);
};

LList::LList ()
{
  // Empty constructor.
}

LList::LList (int newKey, LList* nextLink)
{
  key=newKey;
  next=nextLink;
}

void LList::printTheList()
{
  LList* currentList = this;
  for (; currentList != NULL; currentList=currentList->next)
    {
      cout << "key = " << currentList->key << endl;
    }
}

// add at the end
void LList::addToTheList(int newKey)
{
  LList* currentList = this;
  LList* newItem = new LList(newKey, NULL);
  LList* prev;

  for (;  currentList != NULL; currentList=currentList->next)
    {
      prev=currentList;
    }

  prev->next = newItem;
}

