// acctList.cc
// P. Conrad, 4/6/2005 
// list of accounts

#include "acct.h"
#include "acctList.h"
#include <iostream>
using namespace std;

// constructor makes an empty list of accounts

AcctList_C::AcctList_C()
{
    numAccounts = 0;
    head = NULL;
    tail = NULL;
}

// copy constructor traverses the original list making a brand new one
AcctList_C::AcctList_C(const AcctList_C &orig)
{
  // start with an empty list
  numAccounts = 0;
  head = tail = NULL;

  // for each item in the original list, make a new node in the
  // new list with matching account information add it to the current list

  for (Node *p=orig.head; p!=NULL; p=p->next)
    addAccount(*(p->acct));
}

void AcctList_C::addAccount(Acct_C &a)
{
  Node *p;

  p = new Node;
  p->acct = new Acct_C(a.getAcctNum(), a.getName());
  p->next = NULL;

  if (head==NULL)
    head = tail = p;
  else 
    {
      tail->next = p;
      tail = p;
    }
  numAccounts++;
}


void AcctList_C::printAllAccounts()
{
  for (Node *p=head; p!=NULL ; p=p->next)
    cout << "\t" << p->acct->getAcctNum() 
	 << "\t" << p->acct->getName() << endl;

}

// question.. what if you just wrote p->getAcctNum.  Would that work?
// why or why not?














