Does anyone know how to create circular linked list whose links are numbered from 1 to n specified by the user?
Yes.... yes, I do.
I love answering questions sometimes!
Create a circular linked list class and add an index member variable that will always be +1 to the input.
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
how do i do it, not quite clear on it, any help would greatly be appreciated.
Here is a code snippet of a function to initialize something using a value:
void FillMyArray(int ArrayToBeFilled[], int TopValueToBeInserted)
{
for(int i = 1; i<=TopValueToBeInserted;i++)
{
ArrayToBeFilled[i] = i;
}
}
That should be enough to fill it
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
void FillMyArray(int ArrayToBeFilled[], int TopValueToBeInserted)
{
for(int i = 1; i<=TopValueToBeInserted;i++)
{
ArrayToBeFilled[i] = i;
}
}
The usual (and correct) idiom is like this.
for(int i = 0; i < TopValueToBeInserted; i++)
An array of size N is indexed from 0 to N-1.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Actually, for what he's asking for... I do need to make a modification, but not what you are saying.
ArrayToBeFilled[i-1] = i;
He wants it to be 1 to N for values.
But thanks for pointing that out!
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
Or using the usual idiom,
for ( int i = 0; i < TopValueToBeInserted; i++ )
{
ArrayToBeFilled[i] = i + 1;
}
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
Apparently you don't trust the people you ask questions to. Otherwise you wouldn't post the same question on multiple sites. That's a pet peeve of mine, so if you're going to post identical threads and identical replies, at least include what you've been shown in your identical thread on the other sites as well so that we know where you stand.
Yes, I lurk in a lot of forums besides Daniweb.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401