Resetting a 2D array

Revision en5, by rezaulhsagar, 2017-04-25 17:40:00

Hi, In a graph problem, I need to memset a whole 2D array with a large value that denotes INFINITY.

Currently, I am doing this by running a O(N*N) loop.

const int maxx = something;
int grid[maxx+7][maxx+7]
for(int i=0;i<maxx;i++){
   for(int j=0;j<maxx;j++){
      grid[i][j] = large_value;
   }
}

Is there a better way to do this?

Also, I have tried memset function.

memset(grid,127,sizeof grid) resets all values to 2139062143

memset(grid,128,sizeof grid) resets all values to -2139062144

Why memset works like this? Thanks in advance!

Tags #memset, #graph

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English rezaulhsagar 2017-04-25 17:42:05 3
en6 English rezaulhsagar 2017-04-25 17:40:46 0 (published)
en5 English rezaulhsagar 2017-04-25 17:40:00 6
en4 English rezaulhsagar 2017-04-25 17:39:03 55
en3 English rezaulhsagar 2017-04-25 17:37:32 2 Tiny change: 'unction.\n`memset(' -> 'unction.\n\n`memset('
en2 English rezaulhsagar 2017-04-25 17:36:56 25
en1 English rezaulhsagar 2017-04-25 17:35:25 528 Initial revision (saved to drafts)