how to keep only 2 rows of matrix

May 4, 2013 at 7:40pm
How can I keep just 2 rows using modular arithmetic at the time of 2 D array, meaning I do not need to store the entire table, since I have a lot of items. This array will be used for knapsack problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

cin>>sizeDesired >> number;

  //create dynamic 2D array;
   	int **arr = new int*[sizeDesired];
	for(int i = 0; i < sizeDesired; ++i)
	{
		arr[i] = new int[number];
	}

//process some data
for (int k=0; k<sizeDesired; k++)
{
for (int n =0; n<number n++)
{
cin>> arr [k] [n];
//after 2 roows are full, I need to create 1 new row and delete the top row.
// how do I do that? Thanks!
}
}
	
Last edited on May 4, 2013 at 11:32pm
May 4, 2013 at 11:32pm
help!!!
May 4, 2013 at 11:42pm
In your example you've already created all the row, so why do you ask how to create a new one ?
May 4, 2013 at 11:49pm
Maybe, I should not create the entire matrix before, instead just generate new row once the first two rows are full and then delete the first row.

what do you think?

Thanks!
May 5, 2013 at 12:16am
Why not simply reuse a row instead of deleting+creating one ?
Last edited on May 5, 2013 at 12:16am
May 5, 2013 at 1:07am
thank you
Topic archived. No new replies allowed.