Sorted vector

Hello everyone....

I have a vector of POINT:

typedef vector<POINT> vectPoints;

I'd like to have an ordered array of this vector so I can remove and
insert "sources of POINT" in ordered way... so I thought about sets...

It is possible to have something like:

typedef set<int, vectPoints> array_of_POINTS

so I could have that int as order key?...

If yes, how I could "insert" since doing

array_of_POINTS afP;
vectPoints vp;
....
afP.insert(idxorder, vp);

doesn't work?...

thanks to all!
Ciao
Luigi
0
Luigino
3/3/2010 11:50:01 AM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
1035 Views

Similar Articles

[PageSpeed] 36

Luigino wrote:
> Hello everyone....
> 
> I have a vector of POINT:
> 
> typedef vector<POINT> vectPoints;
> 
> I'd like to have an ordered array of this vector so I can remove and
> insert "sources of POINT" in ordered way... so I thought about sets...
> 
> It is possible to have something like:
> 
> typedef set<int, vectPoints> array_of_POINTS
> 
> so I could have that int as order key?...
> 
> If yes, how I could "insert" since doing
> 
> array_of_POINTS afP;
> vectPoints vp;
> ...
> afP.insert(idxorder, vp);
> 
> doesn't work?...

I'm not quite sure what you want to do here. What determines the ordering of the
POINT objects?

But normally you would create a comparison class Comp, and then do

typedef std::set<POINT, Comp> PointSet;

PointSet pointSet;

Then if you insert points in pointSet, they will be maintained in sorted order
according to Comp.

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 12:29:31 PM
HI David,

> But normally you would create a comparison class Comp, and then do
>
> typedef std::set<POINT, Comp> PointSet;
>
> PointSet pointSet;

ehm, I am a bit lost... with this do you mean something like:

typedef std::vector<POINT> vect_of_points;
typedef std::set<vect_of_points, Comp> vect_of_ordered_sources;

vect_of_points v;
v.resize(...);
for(int i=v.size()-1; i>0; i--) {
    v.at(i).x = value_x;
    v.at(i).y = value_y;
}
....
vect_of_ordered_sources.insert(v, 0);
vect_of_ordered_sources.insert(v1, 2);   // where v1 has similar
for(..) code as v
vect_of_ordered_sources.insert(v2, 1);   // where v2 has similar
for(..) code as v

so the order will be:

v, v2, v1... right?...

Thanks a lot!
Ciao,
Luigi
0
Luigino
3/3/2010 1:11:45 PM
Luigino wrote:
> ehm, I am a bit lost... with this do you mean something like:
> 
> typedef std::vector<POINT> vect_of_points;
> typedef std::set<vect_of_points, Comp> vect_of_ordered_sources;
> 
> vect_of_points v;
> v.resize(...);
> for(int i=v.size()-1; i>0; i--) {
>     v.at(i).x = value_x;
>     v.at(i).y = value_y;
> }
> ...
> vect_of_ordered_sources.insert(v, 0);
> vect_of_ordered_sources.insert(v1, 2);   // where v1 has similar
> for(..) code as v
> vect_of_ordered_sources.insert(v2, 1);   // where v2 has similar
> for(..) code as v
> 
> so the order will be:
> 
> v, v2, v1... right?...

Luigi:

Did you actually read what I wrote? I was suggesting that you do not need the
vector at all. Just use a set with the correct comparator, and it will be
maintained in sorted order.

It is stil not clear to me what is determining the ordering of your points. If
you want to place POINTs in order, you need a comparison operator for POINTs

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 1:22:33 PM
HI David,

> Did you actually read what I wrote? I was suggesting that you do not need the
> vector at all. Just use a set with the correct comparator, and it will be
> maintained in sorted order.
>
> It is stil not clear to me what is determining the ordering of your points. If
> you want to place POINTs in order, you need a comparison operator for POINTs

I am meaning about multiple array of POINTs like I have different
polyline's graphic ... like:

polyline graphic 1: { (0,0);(1,33);(2,67),... }
polyline graphic 2: { (0,0);(1,54);(2,39),... }

and so on...

just since I have different checkboxes where I could add/remove
graphic I was asking what I said in the previous answer using insert()/
erase()

Luigi
0
Luigino
3/3/2010 1:37:49 PM
Luigino wrote:
> HI David,
> 
>> Did you actually read what I wrote? I was suggesting that you do not need the
>> vector at all. Just use a set with the correct comparator, and it will be
>> maintained in sorted order.
>>
>> It is stil not clear to me what is determining the ordering of your points. If
>> you want to place POINTs in order, you need a comparison operator for POINTs
> 
> I am meaning about multiple array of POINTs like I have different
> polyline's graphic ... like:
> 
> polyline graphic 1: { (0,0);(1,33);(2,67),... }
> polyline graphic 2: { (0,0);(1,54);(2,39),... }
> 
> and so on...
> 
> just since I have different checkboxes where I could add/remove
> graphic I was asking what I said in the previous answer using insert()/
> erase()

Ah, so you want to place arrays of POINTs in order? If so, you need a comparison
operator for arrays (or vectors) of points.

Are all these arrays the same length?

What determines their ordering?

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 1:49:18 PM
> Ah, so you want to place arrays of POINTs in order? If so, you need a comparison
> operator for arrays (or vectors) of points.

As like as I typed in the code example before?...

> Are all these arrays the same length?

yes, all these arrays are of same lenght (practically the X length of
the desktop)...

> What determines their ordering?

Just an int index so first checkbox would be idx=0, second checkbox
would be idx=1 and so on..

0
Luigino
3/3/2010 2:10:29 PM
Luigino wrote:
> 
>> Ah, so you want to place arrays of POINTs in order? If so, you need a comparison
>> operator for arrays (or vectors) of points.
> 
> As like as I typed in the code example before?...
> 
>> Are all these arrays the same length?
> 
> yes, all these arrays are of same lenght (practically the X length of
> the desktop)...
> 
>> What determines their ordering?
> 
> Just an int index so first checkbox would be idx=0, second checkbox
> would be idx=1 and so on..

Luigi:

I guess I don't understand the problem then. Why not just use a vector of
vectors with these indices?

typedef std::vector<std::vector<POINT>> VecVector;

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 3:12:50 PM
HI,

> I guess I don't understand the problem then. Why not just use a vector of
> vectors with these indices?
> typedef std::vector<std::vector<POINT>> VecVector;

Actually it's a vector of vectors but there's a disadvantage with
it... let's assume I have 4 checkboxes where each checkbox represents
a source:

1) I select first checkbox and insert into vector_of_vectors as idx =
0;
2) I select second checkbox and insert into vector_of_vectors as idx =
1;
3) I deselect first checkbox and erase from vector_of_vectors of idx=0
position
4) I deselect second checkbox and erase from vector_of_vectors of
idx=1 position <---- here I get an Assertion Failure for right because
now the array of vectors is sized = 1 and there's no idx=1....

or even if I select second checkbox and insert into vector_of_vectors
as idx=1 (vectors_of_vector.insert(vectors_of_vector.begin()+idx,
vector) ) and it goes into assertion failure because there's no
idx=1...

Indeed having an "ordered by int" set I could have something like:

vectors_of_vector.insert(idx, vector); where it would insert for that
idx and when I need to remove it would find the idx I want and remove
it...

0
Luigino
3/3/2010 3:59:52 PM
Luigino wrote:
> HI,
> 
>> I guess I don't understand the problem then. Why not just use a vector of
>> vectors with these indices?
>> typedef std::vector<std::vector<POINT>> VecVector;
> 
> Actually it's a vector of vectors but there's a disadvantage with
> it... let's assume I have 4 checkboxes where each checkbox represents
> a source:
> 
> 1) I select first checkbox and insert into vector_of_vectors as idx =
> 0;
> 2) I select second checkbox and insert into vector_of_vectors as idx =
> 1;
> 3) I deselect first checkbox and erase from vector_of_vectors of idx=0
> position
> 4) I deselect second checkbox and erase from vector_of_vectors of
> idx=1 position <---- here I get an Assertion Failure for right because
> now the array of vectors is sized = 1 and there's no idx=1....
> 
> or even if I select second checkbox and insert into vector_of_vectors
> as idx=1 (vectors_of_vector.insert(vectors_of_vector.begin()+idx,
> vector) ) and it goes into assertion failure because there's no
> idx=1...
> 
> Indeed having an "ordered by int" set I could have something like:
> 
> vectors_of_vector.insert(idx, vector); where it would insert for that
> idx and when I need to remove it would find the idx I want and remove
> it...

Luigi:

Then at any given stage, some of the indices might be missing?

Perhaps

std::map<int, std::vector<POINT>>

would work for you.

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 4:34:35 PM
HI

> std::map<int, std::vector<POINT>>
> would work for you.

That would mean if I use this std::map and I do

mymap.erase(3);

it would search for the int = 3 in the map then erase that element, so
the same about

mymap.insert(2, vector_of_points);

that would insert with int = 2, right?...

Thanks
Ciao
Luigi
0
Luigino
3/3/2010 4:44:47 PM
Luigino wrote:
> HI
> 
>> std::map<int, std::vector<POINT>>
>> would work for you.
> 
> That would mean if I use this std::map and I do
> 
> mymap.erase(3);
> 
> it would search for the int = 3 in the map then erase that element, so
> the same about
> 
> mymap.insert(2, vector_of_points);
> 
> that would insert with int = 2, right?...

Luigi:

Cloe, but not quite.

Rather than guessing you might look at the documentation of std::map.

The elements of std::map are std::pair<const Key, Type>.

-- 
David Wilkinson
Visual C++ MVP
0
David
3/3/2010 5:57:46 PM
Reply:

Similar Artilces:

How can I sort by font color?
I have a large spreadsheet with roughly 2800 rows of data. A coworker has formatted individual cells in red in which she has made changes and I need to extract only those rows of data...is there an automated way to do this? Thanks, Ryan Check out Chip Pearson's site http://www.cpearson.com/excel/SortByColor.htm -- Regards Ron de Bruin (Win XP Pro SP-1 XL2000-2003) www.rondebruin.nl "Ryan" <anonymous@discussions.microsoft.com> wrote in message news:00c801c3d3c5$93ffd1a0$a601280a@phx.gbl... > I have a large spreadsheet with roughly 2800 rows of > data. A c...

Manual sort in a pivot chart/pivot table
My goal is to change the order of 4 row lablels. They are all text, and I have to choose the order (not alphabetical). I got as far as clicking on the arrow next to Row Label on the table, going to More Sort Options and then choosing Manual Sort. HOWEVER, where/when do I grab the labels to "drag" them to the right order? I have tried clicking on the table itself and clicking on the chart but there is no dragging happening. I can't find any detailed info on Manual Sort in the Help box, and so I'm stuck. Thanks in advance! You can click on the cell containing label an...

Sort Error in Crystal Report Code with VS 2005
I get an Invalid Index error in the following code; please help... Invalid Index. (Exception from HRESULT:0x800200B (DISP_E_BADINDEX) string sortField = "City"; ReportDocument objReport = new ReportDocument(); objReport.Load("MyReport"); FieldDefinition FieldDef; FieldDef = objReport .Database.Tables[0].Fields[sortField]; //ERROR HERE objReport.DataDefinition.SortFields[0].Field = FieldDef; objReport.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder; ...

How do I sort letters before numbers in Excel?
I want to sort contract numbers in Excel the same way we do in our filing system at work. Our contracts contain both numbers and letters, but excel won't let me sort the contracts with the letters first. For example: Excel sorts our contract numbers like this: 123ABC123 ABC123123 ABCABC123 .... and so on I want to sort them like this: ABCABC123 ABC123123 123ABC123 .... etc. Is there any way to do this in excel? I've tried creating new lists, but they don't seem to make a difference, particularly with the numbers. The default in excel is set to sort numbers before letter...

Update defined name ranges after sort
My application requires adding records (rows) on an ongoing basis, then sorting on column A (Category). How do you get named ranges to update to their new location after sorting? If I manually move a row, the referencing hyperlink follows. However a data sort does not update the name pointer and I have to go in and edit the range. Insert>Name>Define> give the name and use OFFSET() formula as below in refers to =OFFSET(Sheet1!$A$1,,,COUNTA(Sheet1!$A:$A)) If this post helps click Yes --------------- Jacob Skaria "JFU" wrote: > My application r...

Filters
When I click on a column filter button and select "sort A to Z" the filter button picture changes to show an up or down arrow indicating that this column was sorted ascending or decending. I am using Excell 2007; I'm not sure this applies to previous versions. Is there a way to interrogate the filter or column to determine if the column filter is showing the up or down arrow indicating that it is sorted. Thanks for any help Fred ...

Arranging mail in inbox does not sort properly
When trying to organize items in the inbox by importance you would expect the items after the important items to be listed in chronological order....why doesn't this happen? This is the way it happened in Outlook 98...any help is appreciated.... Go to View | Current View | Customize Current View, click the Sort button, and set your preferred sorting columns and sort order there. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:066e01c3daf3$f0e4f230$a10128...

Sorting worksheets alphabetically (in Turkish specific characters)
This scripts sorts the worksheet regularly, except it -naturally- puts the sheets with turkish specific characters to wrong place. Because Turkish specific characters have greater ASCII values. For example we have a lowercase "i" with no dot on, and it is just before letter "i" in the alphabet (but not in the ASCII table:) -What is the most straight forward method to handle specific characters in your opinion? sorry this is the code: Public Sub SortSheets() Dim SheetCount As Integer Dim i As Integer Dim j As Integer SheetCount = Worksheets.Count For i = 1 To Shee...

Conditional Sorting in Excel
I have what im hoping is a simple question. Basically, I am organizing an event for 60 people and need to come up with table assignments for 4 separate events. I am trying to put these 60 people into groups of 10, but I don't want people from the same cities sitting together and I also don't want people to sit with the same person multiple times (or at least as well as possible). I basically have a 2 column spreadsheet - A is attendee names and B is cities. Is there anyway that I can generate 4 distinct (or close to) lists - each list containing 6 groups of 10? ...

sort text numbers as number
I have a list like this 1-apple 2-orange .... 11-pears 12-grapes.. Now when I sort it, it will sort number 2 after number 12 because it takes it as text, how can I have Excel sort it by the numeric value of the begining of the filed? -- Jacob Fleischman Federal plastics ltee 514-342-5411 jacob@fedplast.com Jacob, You can make a helper column, and sort on that column. =LEFT(A2,SEARCH("-",A2)-1) This should yield the number part at the beginning of the cell - it looks for a hyphen. It will fail if it doesn't find a hyphen; the formula can be expanded to behave more nicely i...

Reporting Service - Parameters
Hi, I'm trying to use the SDK example for Dynamic Column Sorting. I don't understand how to build the parameters: CRM_SortField and CRM_SortDirection. Where exactly I put the parameters value? Thanks, Nurit ------=_NextPart_0001_DB33B892 Content-Type: text/plain Content-Transfer-Encoding: 7bit <Nurit@discussions.microsoft.com> wrote: > I'm trying to use the SDK example for Dynamic Column Sorting. > I don't understand how to build the parameters: CRM_SortField and > CRM_SortDirection. Where exactly I put the parameters value? In the Visual Studio report desi...

"Select names" sort order
No matter what I have tried to do, I cannot get the "select Names" to change its sort order from first, last name to last, first. I assume there something that I am missing. Would appreciate help/pointer. Using Outlook 2003 Thanks....JOHN OK....it appears that I can get "Select names" in Last/first sequence if I go into Contact Options and define 'Default "Full Name" order' as last/first. Which then makes all the names displayed, including the name appended to the email address with this sequence....which is bass-ackwards....at least for US ...

EXCEL Sort #2
Sometimes when the cursor is in a singe cell in a spreadshhet and I sort, it will sort all the rowsin all the columns, sometimes it only sorts rows in some columns. The only way I feel safe is to highlight the entire working area, then sort the spreadshhet. George Lawshe George@Lawshe.com ...

Scrambled Sorting
Using Win XP/ Office 03 - As anyone seen or heard of a situation where a user sorts a mail folder by From or To, but it doesn't completely work? There is a group of items listed for "From Joe Schmoe" - but after 6 messages from Joe, the group included messages from Sally and Mike and Amber. counting them as "From Joe Schmoe" in the over all count. I think this is due to the folder size, but I wanted to ask out here in case anyone as read anything. Didn't find anything on the KB on it. Thanks, -Monica davison@fr.com ...

SORTING PROBLEM: Can I sort Data across several spreadsheets
Help Please! I have a data set that spans several worksheets, since a single worksheet can only handle 2^16 = 65536 rows in Exel. Is there a way to sort my data across all my spreadsheets? or am I just limited to doing only 1 worksheet. I would love for it to sort all my data across all spreadsheets (i.e. if line 1 of Sheet4 really belongs on line 3 of Sheet1 if sorting by Time for instance) Please help Anybody!!! ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~ View and post usenet messages directly from http://www.ExcelForum.com/ ...

how to sort A to Z AND 0 to 9?
I don't use Excel much. I would like the following document numbers sorted like this: AR4714a AR4714b AR4714z AR4714aa AR4714ab I'm getting them sorted like this: AR4714a AR4714aa AR4714ab AR4714b AR4714z Is there an easy solution to this? Thank you, Jabber Using your sample data, and assuming it is in cell A1:A5, enter this formula in B1: =LEN(A1) Copy cell B1 and paste it into B2:B5. This generates the length- the number of columns- in your document number. Then when you sort, sort first on column B, and then on column A. What is wrong with that order? -- HTH RP (re...

Sort winners of a golf tournament two ways
In a golf tournament, we have two groups of winners. One group is those players with the lowest gross scores. The second group is those players with the lowest net (gross minus handicap) scores. In the example, 3 players would be rewarded for their highest finish, be it gross or net. They cannot win a prize in both categories. Example: Name Hdc Gross Scr Net Scr Gross Rank Net Rank Bob 12 87 75 6 6 Carl 6 78 72 2 4 Ed 17 ...

Sorting numbers doesn't work correctly
I rarely use Excel, but I need to sort a spreadsheet in which one of the columns has only numbers. For example: 121.593, 121.58, 121.641, 121.61. My expectation was that Sort Ascending would produce 121.58, 121.61, 121.593, 121.641. Instead, the sort produces the following sequence: 121.58, 121.593, 121.61, 121.641. In other words, it doesn't seem to understand that the two-digit numbers (after the point (.)) go before the three digit numbers. Is there a workaround? I don't think I understand.. why would 121.61 go before 121.593 if you were sorting ascending.. -- Bearacad -...

Sorting #47
Sorting issue I have a column "c1" that is a name list and am trying to get "C2" to sort alphabeticaly by "c1." I also need "c3" and "c4" to follow the same as "c2". Any suggestions would help greatly. Thank you Jeremy C1 C2 C3 C4 Capital Body Shop Capital Body Shop 37.05 37.05 Cars For Less Cash Sale Cash Sale 3,143.66 0 Central Auto Chico's Cleburne RV Cleburne RV 1,982.77 121.89 Hi J...

Sorting Alphabetically
I often have to create spreadsheets that list our clients and the revenue associated with them. I then have to give subtotals by the first letter of the client's last name. You see each employee is responsible for a letter. How do I sort by the first letter of a last name and then do subtotals for each letter of the alphabet? No need =SUMPRODUCT((LEFT(B4:B14)="a")*C4:C14) or where a2 contains a =SUMPRODUCT((LEFT(B4:B14)=a2)*C4:C14) -- Don Guillett SalesAid Software donaldb@281.com "Jack" <backformore2000@yahoo.com> wrote in message news:OG0l7sz%23EHA.4...

Grouping and sorting
I have an inventory report that I need help with. I have a monthly report that shows all items despersed each month that shows each requisition and items ordered on that requisition. This report is sorted and grouped by department. I now need to creat a summery report that only shows the departments billing code, the department name, and the total amount charged for each requisition. This must be grouped by department the sorted by billing code. The three fields of the db used are Cust2 (department code),Prime (main billing code), and DTL (secondary billing code). I have been ...

How to expand columns when sorting
On my computer with Office 2003 installed, when I want to sort on a column, I select the column, click on Sort Ascending, Excel would prompt me that it found data in the adjacent field and if I want to expand the selection. That's how sorting is done on my computer. Today I had to use someone else's PC and it has Office 2003 too. However, when doing sorting, it doesn't prompt me and just sort that column only. How to make Excel prompt me for this? First, I wouldn't let excel guess at my range to sort. I'd always select the range and do Data|sort. But when you selecte...

Sorting in ascending order in publisher
My question is a simple one, how do I sort the contents of a colum into alphabetical order after it has been created. I thought it would be just a case of high lighting the colum and click a sort button, but i can´t seem to find an easy way of doing it, Thanks Copy into Word, sort, copy back into Publisher -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Barry Harper" <BarryHarper@discussions.microsoft.com> wrote in message news:236216A1-F364-4355-8C66-8A3F9392840D@microsoft.com... > My question is a simple...

Sorting Project that Requires Math Skills
Dear Math People: I have an Excel sheet of 120 pages, with 5 cards on each page with a total of 600 cards. I am going to Office Max where they will make a total of 5 cuts. I need to figure out how to sort my cards (they are numbered 1-600 accordingly) so that when they make the cuts and then stack the 5 piles one on top of the other, they will be in order 1-600. Any takers? I'm not sure I understand fully - do you mean 120 pages (from one worksheet) when printed? Do your 5 cards per page appear under each other, so that you will have a right (or left) margin to crop off, and t...

Sorting with sumif function
HI, I have a worksheet with 5 columns of data and 100 rows. in one of the columns I have a sumif formula. When I try to sort the data the cell reference in the sumif column doesn't change however, the other column do change. Is this normal or am I doing something wrong? Thanks for any help Check if your reference is absolute. See help for "Switch between relative, absolute, and mixed references" ---Please click "yes" if this post helped you!--- Greatly appreciated Eva "ram" wrote: > HI, > > I have a worksheet wi...