Hi,
I have a list which contains numeric strings. The numeric strings in list may start with any number from 1 to 9 (it doesn't start with "0"). Now i need to find three top occurrences in the list.
Ex:
1234
2345
2343
4356
6434
2343
2222
4545
6666
6653
top three occurrences in the above list respectively are 2,6,4.
Loading
VulpesPosted Sep 28, 2011, 8:06 AM
Karthik AgarwalPosted Sep 28, 2011, 7:26 AM
VulpesPosted Sep 28, 2011, 7:12 AM
Incidentally, why are you resizing arrays when the List
Karthik AgarwalPosted Sep 28, 2011, 6:42 AM
What about my other question?
By default all the array elements will be "undefined values" if i just create it as follows:
String ^ copy = "";
array
for(int i = 0; i < 6; i++)
{
Array::Resize(lang, lang->Length + 1);
lang[lang - 1] = lang[lang - 1] + copy;
}
Due to some operation i am missing the last element of the array, which shows up as undefined value. Is there a way how i can validate this i.e i want to be sure that all the elements of the array are valid before doing some operation on the array.
I want do as
if(lang[lang - 1] != null) //null how we do it in "C"
{
//my operation on "lang" array
}
VulpesPosted Sep 28, 2011, 6:14 AM
Karthik AgarwalPosted Sep 28, 2011, 1:06 AM
VulpesPosted Sep 27, 2011, 11:54 AM
Karthik AgarwalPosted Sep 27, 2011, 11:18 AM
VulpesPosted Sep 27, 2011, 11:14 AM
Karthik AgarwalPosted Sep 27, 2011, 10:57 AM
If i write the line
instancename = new classname();
classname(void)
{
language_string_id = gcnew array
}
~classname(void)
{
delete language_string_id;
}
The text marked in red contains data which i load when i call it with 1st instance, will be lost if i create instance as you stated. So i tried writing as below:
classname ^ instancename2;
which is showing up a warning c4101 : unreferenced local variable. Can i use it that way or is there any other way to do?
VulpesPosted Sep 27, 2011, 10:20 AM
Karthik AgarwalPosted Sep 27, 2011, 8:50 AM
and for the second question i am asking how to declare an instance if i should not populate the array in the class again. If i write a line like this
static namespace::classname ^ instancename;
instancename= gcnew namespace::classname ();
again when i want to create instance of the same class for second time the array gets loaded again so i declared as follows,
LanguageTable ^ PrintLanguageData;
will this work or else should i change that?
VulpesPosted Sep 27, 2011, 8:43 AM
Karthik AgarwalPosted Sep 27, 2011, 7:57 AM
I am incrementing my array size
Array::Resize(lang, lang->Length + 1);
after that sometimes one of the array element is not defined and hence causing break to the normal execution. how to validate whether anything is validated or not?
And more thing is i have created an instance to a class as follows:
static namespace::classname ^ instancename;
instancename= gcnew namespace::classname ();
Now i want create instance in some other place same as above but if i do that a array which is written in above class is getting loaded again which causing the length and elements to get loaded again. so how can i avoid this.
I wrote like this which is working fine but showing a warning. will this work perfectly or should i change that.?
classname ^ instancename2;
Karthik AgarwalPosted Sep 27, 2011, 7:04 AM
I think Single::Parse(fStr); will generate and exception if it couldn't be parsed right? anyways the method i stated is good i think. anyways thanks vulpes.
VulpesPosted Sep 27, 2011, 7:01 AM
VulpesPosted Sep 27, 2011, 5:47 AM
VulpesPosted Sep 26, 2011, 5:34 AM
Karthik AgarwalPosted Sep 26, 2011, 5:24 AM
its like i need binary value to occupy 5 places even though it is lees than that. can you please tell me how i can make that happen?
Karthik AgarwalPosted Sep 23, 2011, 9:30 AM
VulpesPosted Sep 23, 2011, 9:01 AM
Karthik AgarwalPosted Sep 23, 2011, 8:39 AM
Karthik AgarwalPosted Sep 23, 2011, 8:15 AM
VulpesPosted Sep 23, 2011, 8:12 AM
Karthik AgarwalPosted Sep 23, 2011, 7:36 AM
what does that 48 mean?
results[i] = 100000 * results[i] + i;
what does this 100000 mean and why are you multiplying it with results[i] and adding with i?
VulpesPosted Sep 23, 2011, 7:09 AM
#include "stdafx.h"
using namespace System;
using namespace System::Collections::Generic;
int main(array
{
array
{
"1234",
"2345",
"2343",
"4356",
"6434",
"2343",
"2222",
"4545",
"6666",
"6653"
};
List
array
for each(String ^s in list)
{
int i = s[0] - 48;
results[i]++;
}
for(int i = 1; i < 10; i++)
{
results[i] = 10 * results[i] + i; // EDITED
}
Array::Sort(results);
Array::Reverse(results);
Console::WriteLine("Top 3 occurrences are\n");
for(int i = 0; i < 3; i++) Console::WriteLine("{0} occurs {1} time(s)", results[i] % 10, results[i] / 10); // EDITED
Console::ReadKey();
return 0;
}