You could write a function like:
int** create_2d_array(int rows, int cols)
{
int** array = new int*[rows];
for (int i = 0; i < rows; i++)
array[i] = new int[cols];
return array;
}
//...
int** array = create_2d_array(5,5);
array[0][0] = 1;
array[3][4] = 1;
//etc
Replacing int with ...
Search found 3 matches
- Fri Aug 01, 2008 8:52 pm
- Forum: C++
- Topic: Dynamic allocation of matrix?
- Replies: 5
- Views: 3556
- Thu Jan 31, 2008 7:00 am
- Forum: C++
- Topic: sorting using algorithm
- Replies: 1
- Views: 2005
sorting using algorithm
Is this the correct way to use sort?
//include files (iostream, algorithm, vector, etc.)
class C
{
//...stuff
bool operator < (const C& r) const
{
if (some_attribute < r.some_attribute)
return true;
else
return false;
}
}
int main()
{
///
vector<C> units;
load_units(units);
sort ...
//include files (iostream, algorithm, vector, etc.)
class C
{
//...stuff
bool operator < (const C& r) const
{
if (some_attribute < r.some_attribute)
return true;
else
return false;
}
}
int main()
{
///
vector<C> units;
load_units(units);
sort ...
- Sun Jan 20, 2008 9:21 am
- Forum: Volume 1 (100-199)
- Topic: 105 - The Skyline Problem
- Replies: 160
- Views: 51365