Hey.. I'm having trouble with some homework.
We are working on VectorList ( kinda like linked list but with vectors - don't ask why.. ) Anyway I have something like this:
#ifndef VECTORLIST_H
#define VECTORLIST_H
#include <iostream>
#include <vector>
using namespace std;
template< typename NODETYPE >
class VectorList
{
public:
VectorList(); // constructor
~VectorList(); // destructor
void insertAtFront( const NODETYPE & );
void insertAtBack( const NODETYPE & );
bool removeFromFront( NODETYPE & );
bool removeFromBack( NODETYPE & );
bool isEmpty() const;
void print() const;
private:
vector< NODETYPE > *vList; // list data as a vector
};
I need to fill in the functions.. my problem is that I do not understand how to use STIL when I have *vList.. its a pointer to the first vector element?
// display contents of VectorList
template< typename NODETYPE >
void VectorList< NODETYPE >::print() const
{
// Fill in the missing code
}
My Idea was to use a for loop on the vector and use cout<< vector[i]<< endl;
to print the vector out..
Problem is that I get all sorts of errors and seg faults.
I do not understand how to access the vector in the function, and how to access its elements.
This is a header file, and in the main we declare an object of VectorList<NODETYPE> IntVector
...
So how can I do this?
Any help with understanding of how this *vList
plays a role here would help a lot and
I'd probably be able to finish the rest..
Also, for isEmpty()
, I assume I can use vList.empty()
.. but since vList is a pointer..
it doesn't work quite well.
== For the constructor/destructor what can I do? I know for destructor I should iterate through the vector and use delete on each element. But shoul
Please explain this to me, I am frustrated =[