list split help

Ok i am trying to create a method to split a list.

In the main method i have

for (i=0; i < 26; i++)
(myHashTable)->split(i,2);

what this does is the first variable "i" is the index position in the vector and the second variable "2" is the number of elements in the list specified at the vector position. So if it was like myHashTable->split(1,2) it would go to the list at the vector position 1 and check to see if the list has more than 2 elements and if the list does have more than two elements then the first two elements stay where they are and the elements past the second element are moved to the list in the index below the current list.

here is the current method i have for split. I know how to move the first element of the list or last element of the list using begin() and end(), but i am not sure how to move all the elements after the certain index in the list.
so if i do split(2,3) it goes to that list in index 2 in the vector and if the list has 5 elements for instance it goes moves all the elements past index 2 in the list. I have tried using splice and insert. Also i am using the stl library for both the vector and lists Any ideas?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void hello<s>::split(int i, int p)
{
list<char*>::iterator it;
	list<char*>& l =ph[i];
it=l.begin();l.end();i++;
	if(l.size()>p)
	{
		
		list<char*>& p = ph[i+1];
p.splice(it,l);
	        
	}

}
Last edited on
ok i figured out how to split, but now i am having trouble with removing the element. Like if list A has {"Andy B", "Amy Dean", "Antonio G", "Andy Roberts",} in it and list A is at index 0. So if i do split(0,2) it will move Antonio G and Andy Roberts to the list at index 1 and also remove those names from the list at index 0.

here is the code i currently have. My problem now is i keep getting a "list iterator not incrementable" Assertion failed message. Any ideas on how to delete the name after i move it. Any help would be greatly appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void hello<s>::split(int i, int p)
{

	ph.resize(size2+1);
	list<char*>& l =ph[i];
	list<char*>::iterator it;
	list<char*>::iterator it2;
	
	if(l.size()>p)
	{
		it=l.begin();
		for(int j=0;j<p;j++)
		{
			it++;
		}
		for (it; it != l.end(); it++)
{	
		list<char*>& p2 = ph[i+1];
		p2.push_back(*it);
		l.remove(*it);
		
		
}
	}
}
Topic archived. No new replies allowed.