www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/11/25/09:47:21

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Subject: (none)
25 Nov 1998 09:47:21 -0800 :
Message-ID: <199811250030.SAA19555.cygnus.gnu-win32@modi.xraylith.wisc.edu>
References: <199811232132 DOT WAA00238 AT dedalus DOT com>
To: Ugo Matrangolo <matra AT dedalus DOT com>
Cc: gnu-win32 AT cygnus DOT com

Ugo Matrangolo <matra AT dedalus DOT com> writes:
> 
> This program works fine under FreeBSD. 
> 
> Can anyone tell me if it is a bug or my fault ?  

Your fault. Sorry.

A hint:

Think of what's happenning:
    
    vector< vector<int> > mymatrix(n);

Here mymatrix is a vector of n elements, where each element is another
vector; the rub is that each element vector is uninitialized!

    for (int i = 0;i < n;i++)
       for (int j = 0;j < n;j++)
          mymatrix[i][j] = 0; 	// <<< matrix[i] is uninitialized!

take a look at vector<T>::reserve which you can use here. 

or, you can simply do something like the following:
  
    for (int i = 0;i < n;i++)
       mymatrix[i].insert (mymatrix[i].begin(), n, 0);

or, you could use vector<T>::push_back().

or, ....

Regards,
Mumit

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019