M
mathon
Hi,
i am currently working on creating a LinkedList, for that I using a
predefined Node-class which offers a LinkedList Toolkit to manipulate
the Linked List (http://www.cs.colorado.edu/~main/chapter5/node1.h). I
develop a Squence-Class which should store a sequence of numbers in a
LinkedList.
My header file of sequence looks like this, respectively the methods
and variables:
I already implemented the two constructors, the desctructor, the
advance and start-method.
I hope they are right defined.
Unfortunately I really have problems with the insert-function.
According to the specification the insert function should insert a node
before the node which the current cursor points to. So therefore I have
to point with the precursor to the node before the node the cursor
points to, but I do not understand how i can find out this
position...(
Does anybody know here how this insert-method could be efficient
defined?
matti
i am currently working on creating a LinkedList, for that I using a
predefined Node-class which offers a LinkedList Toolkit to manipulate
the Linked List (http://www.cs.colorado.edu/~main/chapter5/node1.h). I
develop a Squence-Class which should store a sequence of numbers in a
LinkedList.
My header file of sequence looks like this, respectively the methods
and variables:
Code:
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef std::size_t size_type;
// CONSTRUCTORS and DESTRUCTOR
sequence( );
sequence(const sequence& source);
~sequence( );
// MODIFICATION MEMBER FUNCTIONS
void start( );
void advance( );
void insert(const value_type& entry);
void attach(const value_type& entry);
void operator =(const sequence& source);
void remove_current( );
// CONSTANT MEMBER FUNCTIONS
size_type size( ) const { return many_nodes; }
bool is_item( ) const { return (cursor != NULL); }
value_type current( ) const;
private:
node *head_ptr;
node *tail_ptr;
node *cursor;
node *precursor;
size_type many_nodes;
I already implemented the two constructors, the desctructor, the
advance and start-method.
Code:
sequence::sequence()
{
head_ptr = NULL;
tail_ptr = NULL;
many_nodes = 0;
}
sequence::sequence(const sequence& source)
{
node *tail_ptr;
list_copy(source.head_ptr, head_ptr, tail_ptr);
many_nodes = source.many_nodes;
}
sequence::~sequence()
{
list_clear(head_ptr);
many_nodes = 0;
}
void sequence::start()
{
cursor = head_ptr;
}
void sequence::advance()
{
cursor = cursor->link();
}
Unfortunately I really have problems with the insert-function.
According to the specification the insert function should insert a node
before the node which the current cursor points to. So therefore I have
to point with the precursor to the node before the node the cursor
points to, but I do not understand how i can find out this
position...(
Does anybody know here how this insert-method could be efficient
defined?
matti