Is my understanding of a vector list correct. vector<list<int>>.

The vector holds a list of data type int?

class my_ht_chain
{
public:
	//constructor which creates a table of a certain size 
	my_ht_chain(int size);

	//destructor
	~my_ht_chain();

	//insert a value based on key
	void insert(int key);

	//search for a value based on key
	bool search(int key);

	//delete an item in the list
	void remove(int key);

	//prints out all items stored in hash table
	void show_ht_structure() const;

private:
	//number of vectors to store in array
	int tablesize;

	//table to store key 
	vector<list<int>>* dataTable;

	//used to map a key to a position
	int hashfunction(int key);
};

>>"The vector holds a list of data type int? "

the word list has ambiguity.

A better term(IMO) would be : The vector contains a container in which the contained container is of type int and the contained container is a stl's list container.

so for instance say i did dataTable->at(key) would i be referring to the list or vector? or both?

so for instance say i did dataTable->at(key) would i be referring to the list or vector? or both?

dataTable is a vector.

dataTable is a list

dataTable.front() is the int.

And also I don't think mixing up vectors and list would be a good
idea, unless it really really makes sense to do so.

thanks! it makes a lot more sense its just like when you declare an array. we kind of have to for this hash table assignment. Have to create using seperate chaining method. Will ask for help again if i get stuck.

kind of need help with syntax again.
in my insert method, i am supposed to expand an vector with a list. Not sure what to do within if statement.
Rather how I say at this index in my vector expand sideways a list which stores data values.

void my_ht_chain::insert(int key)
{
	//go through loop to check if hashing function matches vector index
	for(int i=0; i<tablesize; i++)
	{
		//match
		if(hashfunction(key)==i)
		{
			
		}
	}
}

nvm i finally got it work. Thanks thought.

my insert function won't work. :( I got it to work before.

void my_ht_chain::insert(int key)
{
	//go through loop to check if hashing function matches vector index
	for(int i=0; i<tablesize; i++)
	{
		//match
		if(hashfunction(key)==i)
		{
			dataTable->at(i).push_front(key);
		}
	}
}

out of range invalid vector subscript.

nvm i found my mistake it wasn't even in here. It was when i constructor my vector apparently the vector(# of values you wish to assign, what you wish to assign) not other way round.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.