In case of insert or deleting rows and cols, i have to do some work....
For example I have map [2][0],map [2][1], map [2][2], and If I insert a new row at 2 position I have to 'mode' all my map from 2 to n-rows.
Is there any fast way to 'move' data in maps?
Another way can be create a copy of the section I have to move, and paste it into a new location into the map ?
Yes STL map.
But what I want is a method to 'move' map data (data or blocks of data ):
I' d like a function like this :
map_move origin, numberof rows , new_pos
When I use this function I have a new empty space at a known position.
I have :
map[0][0 to n]
map[1][0 to n]
map [2][0 to n ]
I want to insert a new value at 1, so I want :
map[0][0 to n] old map 0
map[1][0 to n] empty new data
map [2][0 to n ] (old map 1
map [3][0 to n ] (old map 2
I want to store information as a spreadsheet. (I dont know if I'm doing a stupid thing but ... )
Imagine I have data on 1x1, 1x2, 2x1 , and 10x1. Using map I only use 4 positions.
Ok, now I want to insert data at row 2.... Initially, I'm not going to have data (so my row 2 are going to be empty)
This is because I'm looking for a 'mover' function for a map.
You don't have to save a blank spot. When you insert data a row 2, just call map::insert. It will move everything over for you. When you want to add data to row two, the call would be:
Ok, if I want to retrive data for each cell, I ask to mymap for data, if there is something I have data, if not the cell is empty. I think this aproach can be interesting to reproduce a spreadsheet data.
Ok, I want to insert and empty row of cells at position 2 ?
Really I want to have the data stored for 2,0-n at 3,0-n and the 3,0-n into 4,0-n.
Sincerely I dont know how to insert data at row 2 and to expect the maps move himself the data from a group of rows to a row+1 new location.
Thanks
Excuse me, The last example was to explain another point of view of my problem.
The map can be map <int,int> or map <int, map<int> > it is the same.
Repeat I want to store data from a spreadsheet, there are cells with value and other not.
So, using a Map can be a good initial aproach to work.
But the problem is when I have to insert or delete rows with data or empty data.
So, maybe I have to use custom code to have internal counters of inserted an deleted rows.
Hey tonnot, I understand you. I think you are thinking you need to have a placeholder for empty data. What I didn't say (but implied) is that you can check for the existance of a key, and if it is not in your map, then it's empty. Does that make sense?
Thanks Kooth.
I know that I dont need to have a placeholder for empty data.
I only ask for a method to 'move' my data and 'insert' is not working for me (or I dont know how to use it ).
Repeat how can do the next using insert :
map [1]=3331
map [2]=2121
map [3]=82121
How can I insert data to have :
map [1]=3331
map [3]=2121
map [4]=82121
And for coder777. I dont want to user vector, because if I have row 1 and 999 (2 rows) I will have 998 empty used positions.