Resetting a 2D array

Правка en2, от rezaulhsagar, 2017-04-25 17:36:56

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.

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!

Теги #memset, #graph

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский rezaulhsagar 2017-04-25 17:42:05 3
en6 Английский rezaulhsagar 2017-04-25 17:40:46 0 (published)
en5 Английский rezaulhsagar 2017-04-25 17:40:00 6
en4 Английский rezaulhsagar 2017-04-25 17:39:03 55
en3 Английский rezaulhsagar 2017-04-25 17:37:32 2 Tiny change: 'unction.\n`memset(' -> 'unction.\n\n`memset('
en2 Английский rezaulhsagar 2017-04-25 17:36:56 25
en1 Английский rezaulhsagar 2017-04-25 17:35:25 528 Initial revision (saved to drafts)