Saturday, June 8, 2013

problems with first attempt at proper modular programming

problems with first attempt at proper modular programming

I am having a problem with my first attempt at a proper go at modular programming....
I was wondering if anyone could suggest a possible direction as to how to approach the solution to the problem
here is my code and once again it is from Laszlo's Book on computational geometry ..the only thing I did different was break it into smaller pieces and a unit header file
The Code
header.h
#ifndef NULL
#define NULL 0
#endif
#ifndef A_H
#define A_H

// -----Definition of Node Class ----------------------------------

class Node{

    protected:
        Node *_prev;
        Node * _next;
        static int cindex;


    public:
        int index;
        Node(void);
        virtual ~Node(void);
        Node *next(void); // accessor
        Node *prev(void); //accessor
        Node *insert(Node*);
        Node*remove(void);
        void splice (Node*);

    };

// ------ end of definition of Node --------------------
//======================================================
//----------Start of Definition of ListNode class ------

template < class T > class List;


template<class T> class ListNode: public Node {

    public:
        T _val;
        ListNode(T val);
        friend class List<T>;


    };

// ------ End of Definition of ListNode class --------------------
//====================================================++
//----------Start of Definition of List class ------

template<class T> class List {

    private:
        ListNode<T> *header;
        ListNode<T> *win;
        int _length;
    public:
        List(void);
        ~List(void);
        T insert(T);
        T append(T);
        T prepend(T);
        List * append(List*);
        T remove(void);
        void val(T);
        T val(void);
        T next(void);
        T prev(void);
        T first(void);
        T last(void);
        int length(void);
        bool isFirst(void);
        bool isLast(void);
        bool isHead(void);
    };









#endif
node.cpp
    #include "header.h"

    int Node::cindex=0;

    Node::Node(void) :
      _next(this), _prev(this)
      {index=cindex++;}

      Node::~Node(void) {}
      Node* Node:: next(void)
      {
        return _next; 

       }


     Node* Node::prev(void)
      {
        return _prev; 

       }

     Node *Node::insert(Node*b){

         b->_next=_next;
         _next->_prev=b;
         b->_prev=this;
         _next=b;
         return b;

         }

    Node*Node::remove(void)
    {

    _prev->_next=_next;
    _next->_prev=_prev;
    _next->_prev=this;
    return this;   
    }
LstNode.cpp
#include "header.h"

template <class T> List <T> :: List(void): _length(0)  //constructor for list
{
    header =new ListNode<T>(NULL); //mind you this uses the LIstNode class
    win=header;

}

template<class T>  List <T>::~ List(void) // weird destructor
{
while (length()>0) {

    first();remove();
    }  
    delete header;

}

template <class T> T List <T> ::insert(T val)
{

win->insert( new ListNode <T> (val));
++_length;
return val;
}

template <class T> T List <T>::prepend(T val)
{  
    header->insert(new ListNode <T> (val));
    ++_l