473,503 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to do this in most simple way? about list of arrays

I want to create a list,
each element is an array of 2 integers,
and I want to sort the list according to the first integer of each
element,
is there a simple way to do this? thanks a lot.
Mar 29 '08 #1
3 1298
On Mar 29, 9:20 am, Atemporal <Atemporal.s...@gmail.comwrote:
Just break down what you said...
I want to create a list,
OK... std::list<Nmylist;
each element is an array of 2 integers,
OK... std::list< boost::array<int,2 myList (or whatever array
structure you like if you don't have the boost library)
and I want to sort the list according to the first integer of each
element,
std::sort(myList, accordingToTheFirstInteger);

bool accordingToTheFirstInteger(boost::array<int,2>& x,
boost::array<int,2>& y)
{
// Put how you want to sort them here. (Odd first, then even? OR
largest to smallest)
// See http://msdn2.microsoft.com/en-us/lib...h1(VS.80).aspx
}

is there a simple way to do this? thanks a lot.
Mar 29 '08 #2
joseph cook wrote:
On Mar 29, 9:20 am, Atemporal <Atemporal.s...@gmail.comwrote:
Just break down what you said...
>I want to create a list,

OK... std::list<Nmylist;
>each element is an array of 2 integers,

OK... std::list< boost::array<int,2 myList (or whatever array
structure you like if you don't have the boost library)
>and I want to sort the list according to the first integer of each
element,

std::sort(myList, accordingToTheFirstInteger);

bool accordingToTheFirstInteger(boost::array<int,2>& x,
boost::array<int,2>& y)
{
// Put how you want to sort them here. (Odd first, then even? OR
largest to smallest)
// See http://msdn2.microsoft.com/en-us/lib...h1(VS.80).aspx
}

>is there a simple way to do this? thanks a lot.
An even simpler way would be
std::map<int, intData;
--
Jim Langston
ta*******@rocketmail.com
Mar 29 '08 #3
std::sort(myList, accordingToTheFirstInteger);
Of course i intended to type

std::sort(myList.begin(), myList.end(), accordingToTheFirstInteger).
Mar 29 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
4671
by: Roy Riddex | last post by:
2nd post of the day! I'm just learning about Arrays at College and have met a problem. I have 5 text boxes for number input, a command button to add the numbers to the array, and a command button...
38
3478
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
7
4108
by: jmac | last post by:
Greetings fellow programmers, I have created a C program that has a few bugs and would like to get some help with working them out. Here is a list of the problems that I am experiencing: -...
5
7223
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
51
8207
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
8
5094
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
73
4536
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
4
2450
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
24
3401
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.