Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Edge??

0 views
Skip to first unread message

Trumpour Adam Paul

unread,
Apr 7, 2001, 2:16:31 AM4/7/01
to
One question about assignment 6. In order to use the Edge type, we need
to treat it as a 2-element array, correct? And in order to do that, we
need to declare any variables of type Edge as "Edge blah = new
int[2]". If we do this in the function first(), for example, aren't we
going to end up with a memory leak when the function ends, since after
returning the edge we have no chance to deallocate the memory? Or perhaps
I'm completely missing something here...
Any input (preferably constructive) would be much appreciated!
Thanks.

Cheng Adrian Yu-Chen

unread,
Apr 7, 2001, 10:49:00 AM4/7/01
to Trumpour Adam Paul
Are you the same guy that asked me the same question on Tuesday? Could
you please send me your program. I will see if there is a way to get
around with it by rearranging your log flow a bit.

-- Adrian

John Wu

unread,
Apr 8, 2001, 1:12:32 AM4/8/01
to
On Sat, 7 Apr 2001, Trumpour Adam Paul wrote:

> One question about assignment 6. In order to use the Edge type, we need
> to treat it as a 2-element array, correct? And in order to do that, we
> need to declare any variables of type Edge as "Edge blah = new
> int[2]".

This assumption is INCORRECT. Edge is just an interger pointer. In other
words it is just a reference to a particular element in the matrix array.

For example, given a 5x5 array matrix, ie. matrix[25], if I want a
reference to an element in matrix array, say matrix[4], then I would have
Edge blah = &matrix[4], which give the address of that array element.

Keep that in mind, each element in the matrix is a possible edge. Even
though the matrix array is a one-dimension array, you are supposed to
treat it as a two-dimension array, and the two-dimension indices of the
matrix array element is your pair of intergers connected by the edge
represented by that element.

.--------..------------..--------..-----------------------..--------.
| o\ /o || John C Wu || o\ /o || Engineering Science || o\ /o |
| ---- || || ---- || University of Toronto || ---- |
`--------'`------------'`--------'`-----------------------'`--------'

"Memory is like an orgasm. It's a lot better if you don't have to fake it."
Seymour Cray commenting on virtual memory


Peter Park

unread,
Apr 8, 2001, 5:14:45 AM4/8/01
to John Wu

On Sun, 8 Apr 2001, John Wu wrote:

> This assumption is INCORRECT. Edge is just an interger pointer. In other
> words it is just a reference to a particular element in the matrix array.

We have to write functions that return an edge's vertices. How would we
do this if Edge only points to an array element? I guess what I'm asking
is how we relate the pointer's value to the array index.

John C Wu

unread,
Apr 8, 2001, 1:17:43 PM4/8/01
to
> We have to write functions that return an edge's vertices. How would we
> do this if Edge only points to an array element? I guess what I'm asking
> is how we relate the pointer's value to the array index.
>

As what I said in the previous response, even though matrix is a
one-dimensional array, you are supposed to treat it as a two dimensional
array. In two D, you will need two numbers to reference an element, and
those two numbers are your vertices connecting the edge. the Edge pointer
value allows you to resolve the one D index of the element in the one-D
arrary, after which you are supposed to use it to resolve the two-D indices
of that element. Read the code in the book, and go to the lab on Monday
morning to talk to a TA.

John C Wu

John Wu

unread,
Apr 8, 2001, 2:47:51 PM4/8/01
to
> We have to write functions that return an edge's vertices. How would we
> do this if Edge only points to an array element? I guess what I'm asking
> is how we relate the pointer's value to the array index.
>

As what I said in the previous response, even though matrix is a


one-dimensional array, you are supposed to treat it as a two dimensional
array. In two D, you will need two numbers to reference an element, and
those two numbers are your vertices connecting the edge. the Edge pointer
value allows you to resolve the one D index of the element in the one-D
arrary, after which you are supposed to use it to resolve the two-D
indices of that element. Read the code in the book, and go to the lab on
Monday morning to talk to a TA.

.--------..------------..--------..-----------------------..--------.

John Wu

unread,
Apr 9, 2001, 1:21:20 AM4/9/01
to
On Mon, 9 Apr 2001, Don McAuslan wrote:

> Hey,


>
> > This assumption is INCORRECT. Edge is just an interger pointer. In other
> > words it is just a reference to a particular element in the matrix array.
>

> This is nowhere in the assignment description. It does not make sense to
> change the scope of the assignment and make it much more difficult that it
> has to be the day before it's due. I do not like this form of
> neo-terrorism and I'm going to implement a 2-element array.
>

The comment I made earlier in responding to a newsgroup question was
meant to help you understand the problem. It was by no means meant to
change the scope of the assignment. The comment made was based on my
understanding of the assignment by doing it myself. Maybe, the word
"INCORRECT" was a bit too strong there. But, I don't know if the
2-element array approach would make the problem any easier to implement or
to understand though.

Don McAuslan

unread,
Apr 9, 2001, 12:47:57 AM4/9/01
to John Wu
Hey,

> This assumption is INCORRECT. Edge is just an interger pointer. In other
> words it is just a reference to a particular element in the matrix array.

This is nowhere in the assignment description. It does not make sense to


change the scope of the assignment and make it much more difficult that it
has to be the day before it's due. I do not like this form of
neo-terrorism and I'm going to implement a 2-element array.

Don McAuslan

=================================================
"Why does a femme gino need firearms?"

don.mc...@utoronto.ca
=================================================

0 new messages