Consider the following program and input file: [code] #include <algorithm> #include <cstdlib> #include <ctime> #include <functional> #include <fstream> #include <iostream> #include <iterator> #include <string> #include <vector> #include "natural_compare.h" struct natural_less: std::binary_function<std::string, std::string, bool> { bool operator()(const std::string& a, const std::string& b) { return natural_compare(a, b) < 0; } }; std::vector<std::string> get_lines(std::istream& in) { std::vector<std::string> v; std::string line; while (std::getline(in, line)) { if (line[0] != '#') v.push_back(line); } return v; } int main() { std::srand((unsigned)std::time(0)); std::ifstream in("test.txt"); if (in) { std::vector<std::string> v = get_lines(in); std::random_shuffle(v.begin(), v.end()); std::sort(v.begin(), v.end(), natural_less()); std::vector<std::string>::const_iterator it = v.begin(); std::vector<std::string>::const_iterator end = v.end(); while (it != end) …

Member Avatar
Member Avatar
+7 forum 18

two static arrays size 10 need to be copied to an empty target array size 20. like this: you copy from the first array the nums till arr1[i] = 0 then you switch to the second array and copy to the nums till arr2[i] = 0. then you switch back, and continue to copy the nums, without copying the '0's. example : arr1[10] = {1,1,1,0,2,2,2,2,0,0) arr2[10] = {3,3,3,3,0,4,4,4,0,5} then the result array will be: result[20] = {1,1,1,3,3,3,3,2,2,2,2,4,4,4,5,0,...0} the thingy i wrote prints all the nums allright except the last ones in the second array. any ideas why? thanx in advance. …

Member Avatar
Member Avatar
+0 forum 7

Hi everyone...I am building a program to input students names(first and last) and also GPA. I have everything working but the sort by last name. Everything works fine, even the GPA sort but the last name sort will not. Please help. Below is the function in my program i am trying to use to do the sort. I am using case 1 of the switch statement to do the GPA and case 2 the last name. [CODE]void Sort(int length, struct student allstud[], int func) { int i, j, flag = 1; // set flag to 1 to start first pass …

Member Avatar
Member Avatar
+0 forum 5

Hi there, I'am developing a snippet for a website widget that will read/fetch data from an XML file, sort it in array's and then show it back to the user - formated as a sentence. [b]Example:[/b] [b]XML sample:[/b] [code=text] <row id="1"> <username>GGR1024</username> <name>Raymond</name> <surname>Saliba</surname> <game>Lotto</game> <won>5000</won> </row> <row id="2"> <username>GGR1111</username> <name>Isabelle</name> <surname>Bonnici</surname> <game>Lotto</game> <won>1000</won> </row> <row id="3"> <username>GGR1024</username> <name>Raymond</name> <surname>Saliba</surname> <game>Lotto</game> <won>2000</won> </row> <row id="4"> <username>GGR1024</username> <name>Raymond</name> <surname>Saliba</surname> <game>Lotto</game> <won>200</won> </row> [/code] So... I read that XML file line by line and put the values in an array, do some functions and then show the formatted data back to the …

Member Avatar
Member Avatar
+0 forum 12

i have a datagridview with checkboxes in my window form and i want to sort my result with textbox without losting checkbox checked value. i place code in textbox_textchange() event. first i fill datatable with label click() [code] Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click cmd = New OracleCommand("select categoryname from subcategory where doctype='" + glbdocid + "'order by categoryname ASC ", dl.con) dim myDataTable as new DataTable adap = New OracleDataAdapter(cmd) adap.Fill(DataTable) DataGridView1.DataSource=myDataTable End Sub Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox9.TextChanged Dim myDataView As New DataView(myDataTable) myDataView.RowFilter = …

Member Avatar
+0 forum 0

Hi all, and thanks for your help, in advance. I 'm stiing here with 2 choices, and I need help deciding which one to take. I want to take certain factors into account(i.e. efficiency, speed) I have values that I want to place into a SortedMap. I can do this in one of two ways: Every record I want insert has an account number. These are not unique, as one account can have more than one item on its name, i.e. an account number can appear more than once. I have a choice of two ways to put them into …

Member Avatar
+0 forum 0

How do I sort an array of struct? For example: struct data { string city; string state; int zip; }; data listing[];

Member Avatar
Member Avatar
+0 forum 6

OK Quicksort IS fast. But what if you just wanna sort 30 items? Then Quicksort becomes a bit of overkill. So what most people then use is the one and only popular "bubblesort", also called "standard exchange sort". Let me present you here with my implementation of another sort(among many others) the "straight insertion sort". It's the same technique cardplayers use to place their cards in order. With the Stopwatch class you can even proof that the straight insertion sort of 10 integers is 3 to 4 times faster then bubblesort! So dump bubblesort! Straight insertion sort is as easy …

Member Avatar
Member Avatar
+1 forum 1

The End.