List of array

S

sara

Hi All,

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;

But I could not use it because of compile error. Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough? Is there any other way which is more
efficient?

Thanks,
Sara.
 
V

V.R. Marinov

Hi All,

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;

But I could not use it because of compile error. Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough? Is there any other way which is more
efficient?

std::list can contain user-defined structure/class.
So I guess this is what you need:

struct myPair{
int first;
int second;
};

std::list<myPair> myList;
 
G

Gianni Mariani

sara said:
Hi All,

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;

But I could not use it because of compile error.

std::list requires the type to be assignable. Arrays are not assignable.
... Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough?

I suspect it is, however no-one can answer your question qithout knowing
how you're using this.
... Is there any other way which is more
efficient?

Efficiency is also platform specific.

If you're after a doubly linked list, std::list is just about as fast as
any other list class you can write.
 
J

Jerry Coffin

Hi All,

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;

But I could not use it because of compile error. Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough?

Only you can really answer that -- we don't know how efficient is
enough.
Is there any other way which is more efficient?

Efficient at what? If I had to make a guess based on experience, the
first thing I'd consider would be using something other than a linked
list. You haven't told us exactly what you're doing, so it's impossible
to say with certainty, but my own experience is that there are _very_
few situations in which a linked list is the ideal data structure.
 
T

terminator

Hi All,

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;

But I could not use it because of compile error. Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough? Is there any other way which is more
efficient?

Thanks,
Sara.

Why should it have pairs of integers?
are you certain you do not need maping(in this case the STL type
'std::map<int,int>' can help)
 
T

terminator

I want to define a list containing pairs of integers. I tried to
define the list as following:
list <int[2][1]> l;
But I could not use it because of compile error. Instead I used the
predefine std::pair class and construct a list of pair. I wonder is my
approach efficient enough? Is there any other way which is more
efficient?

std::list can contain user-defined structure/class.
So I guess this is what you need:

struct myPair{
int first;
int second;

};

std::list<myPair> myList;

so what is the meaning of reuse?
'std::pair' is provided for such purpose.

regards,
FM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,293
Messages
2,571,505
Members
48,192
Latest member
LinwoodFol

Latest Threads

Top