How to find maximum occuring integer(Mode) in an unsorted array of integers? One O(nlogn) approach I could think of is to sort. Is there any other best approach?
I have looked around for a simple answer to this and cannot seem to find on (you wouldn't think a simple thing would be hard!)
How do you sort an array of NSNumbers?
This seems to work (compiler doesn't complain, anyway):
float adsr[4] = {0,1.0/PULSE_SPEED, 0,1};
[sequence setBaseADSR:adsr];
but I want to make it more concise and do this:
[sequence setBaseADSR:{0,1.0/PULSE_SPEED, 0,1}];
How do I do it? In javascript, I'd call stuff in the brackets an "array literal". Not sure if C languages have the same concept or terminology though.
Hello experts,
How can I convert a PSID type into a byte array that contains the byte value of the SID?
Something like:
PSID pSid;
byte sidBytes[68];//Max. length of SID in bytes is 68
if(GetAccountSid(
NULL, // default lookup logic
AccountName,// account to obtain SID
&pSid // buffer to allocate to contain resultant SID
)
{
ConvertPSIDToByteArray(pSid, sidBytes);
}
--how should I write the function ConvertPSIDToByteArray?
Thank you!
I have a form with a collection of checkbox's for a refine search function on my website.
I am trying to pass an array in a form GET but the URL looks like:
/search?filter=foo&filter=bar&filter=green
Is there a better way to pass this in MVC? Possible like
/search?filter=foo,bar,green
Thanks in advance.
I currently have a MapToolKit.html , and two .js files namely map.js and search.js. When i search places like starbucks, they will return me addresses and coordinates stored into an array. I would like to display those multiple values into the html page, not just one value which i currently did it on my coding now.
Here's the source code:
http://www.mediafire.com/?0minqxgwzmx
I want to turn a screen shot from the clipboard into a array data (Red/Green/Blue) in my program. so i guess it's as simple as that. but i don't want to use anything else then the print screen and clipboard if i can?
anyway any questions just ask.
If I have a 2D array that is arranged as follows :
String X[][] = new String [][] {{"127.0.0.9", "60", "75000","UDP", "Good"},
{"127.0.0.8", "75", "75000","TCP", "Bad"},
{"127.0.0.9", "75", "70000","UDP", "Good"},
{"127.0.0.1", "", "70000","UDP", "Good"},
{"127.0.0.1", "75", "75000","TCP", "Bad"}
};
I want to know the frequency of each value .. so I27.0.0.9 gets 2. How can I do a general solution for this ? In Java or any algorithm for any language ?
You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element.
How would you find the unpaired element.
Pair means duplicate. So (3,3) is a pair and (3,-3) is not a pair.
Can someone please write to me source code in Java? I have a task: create a program, that contains two dimensional array (with numbers) and the programm needs to sum zeros in each column and then get out the number of column in which the zeros are least.. thanks!
I have an table view, and the data source returns elements in the wrong order. So I have to reverse the elements in that array which returns the data for each row. How would I do that the most efficient way?
If I have the following plain string, how do I divide it into an array of three elements?
{["a","English"],["b","US"],["c","Chinese"]}
["a","English"],["b","US"],["c","Chinese"]
This problem is related to JSON string parsing, so I wonder if there is any API to facilitate the conversion.
I have xml structure
all data comes here inside CDATA
I am using css file in it to format text and classes are mentioned in xml
Below is the code which shows data but does not format with CSS.
Thanks in advance!
var myXML:XML = new XML();
var myURLLoader:URLLoader = new URLLoader();
var myURLRequest:URLRequest = new URLRequest("test.xml");
myURLLoader.load(myURLRequest);
//////////////For CSS///////////////
var myCSS:StyleSheet = new StyleSheet();
var myCSSURLLoader:URLLoader = new URLLoader();
var myCSSURLRequest:URLRequest = new URLRequest("test.css");
myCSSURLLoader.load(myCSSURLRequest);
myCSSURLLoader.addEventListener(Event.COMPLETE,processXML);
var i:int;
var textHeight:int = 0;
var textPadding:int = 10;
var txtName:TextField = new TextField();
var myMov:MovieClip = new MovieClip();
var myMovGroup:MovieClip = new MovieClip();
var myArray:Array = new Array();
function processXML(e:Event):void
{
myXML = new XML(myURLLoader.data);
trace(myXML.person.length());
var total:int = myXML.person.length();
trace("total" + total);
for(i=0; i<total; i++)
{
myArray.push({name: myXML.person[i].name.toString()});
trace(myArray[i].name);
}
processCSS();
}
function processCSS():void
{
myCSS.parseCSS(myCSSURLLoader.data);
for(i=0; i<myXML.person.length(); i++)
{
myMov.addChild(textConvertion(myArray[i].name));
myMov.y = textHeight;
textHeight += myMov.height + textPadding;
trace("Text: "+myXML.person[i].name);
myMovGroup.addChild(myMov);
}
this.addChild(myMovGroup);
}
function textConvertion(textConverted:String)
{
var tc:TextField = new TextField();
tc.htmlText = textConverted;
tc.multiline = true;
tc.wordWrap = true;
tc.autoSize = TextFieldAutoSize.LEFT;
tc.selectable = true;
tc.y = textHeight;
textHeight += tc.height + textPadding;
tc.styleSheet = myCSS;
return tc;
}
Can someone please give the Java equivalent of the below python (which slices a given array into given parts) which was originally written by ChristopheD here:
def split_list(alist, wanted_parts=1):
length = len(alist)
return [ alist[i*length // wanted_parts: (i+1)*length // wanted_parts]
for i in range(wanted_parts) ]
I don't know any python but can really use the above code in my Java app. Thanks
I am having a problem understanding how array.sort{|x,y| block} works exactly,hence how to use it?
ruby-doc example:
a = [ "d", "a", "e", "c", "b" ]
a.sort #=> ["a", "b", "c", "d", "e"]
a.sort {|x,y| y <=> x } #=> ["e", "d", "c", "b", "a"]
thanks
wondering if it is possible to use an array with Sass as I find my self repeating the following sort of thing:
.donkey
h2
background-color= !donkey
.giraffe
h2
background-color= !giraffe
.iguana
h2
background-color= !iguana
Hi guys, I am new to VB.net and struggling to get out of VB6's way of sending data, I am doing this to send a byte array from my client to server, please advice if this is the right way, thanks:
The sending portion:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim arrNo(3) As Integer
arrNo(0) = 1400
arrNo(1) = 1000
arrNo(2) = 1200
arrNo(3) = 1350
Dim i As Integer
For i = 0 To arrNo.Length - 1
Dim outStream() As Byte = BitConverter.GetBytes(arrNo(i))
Debug.Print(arrNo(i))
serverStream.Write(outStream, 0, outStream.Length)
serverStream.Flush()
Next
End Sub
Hi,
I'm trying to insert a timestamp (hour:min:sec) into a two-byte array and i'm a little confused on how to accomplish this...any help is greatly appreciated!
int Hour = CTime::GetCurrentTime().GetHour();
int Minute = CTime::GetCurrentTime().GetMinute();
int Second = CTime::GetCurrentTime().GetSecond();
BYTE arry[2];
//Need to insert 'Hour', 'Minute', & 'Second' into 'arry'
Thanks!
You have been given an array of size 2n+1 that have n pair of integers(can be +ve, -ve or 0) and one unpaired element.
How would you find the unpaired element.
I have the below configuration where I'm trying to create a test C function that returns a pointer to an Array of Strings and then wrap that using SWIG's carrays.i and array_functions so that I can access the Array elements in Java.
Uncertainties:
%array_functions(char, SWIGArrayUtility); - not sure if char is correct
inline char *getCharArray() - not sure if C function signature is correct
String result = getCharArray(); - String return seems odd, but that's what is generated by SWIG
SWIG.i:
%module Test
%{
#include "test.h"
%}
%include <carrays.i>
%array_functions(char, SWIGArrayUtility);
%include "test.h"
%pragma(java) modulecode=%{
public static char[] getCharArrayImpl() {
final int num = numFoo();
char ret[] = new char[num];
String result = getCharArray();
for (int i = 0; i < num; ++i) {
ret[i] = SWIGArrayUtility_getitem(result, i);
}
return ret;
}
%}
Inline Header C Function:
#ifndef TEST_H
#define TEST_H
inline static unsigned short numFoo() {
return 3;
}
inline char *getCharArray(){
static char* foo[3];
foo[0]="ABC";
foo[1]="5CDE";
foo[2]="EEE6";
return foo;
}
#endif
Java Main Tester:
public class TestMain {
public static void main(String[] args) {
System.loadLibrary("TestJni");
char[] test = Test.getCharArrayImpl();
System.out.println("length=" + test.length);
for(int i=0; i < test.length; i++){
System.out.println(test[i]);
}
}
}
Java Main Tester Output:
length=3
?
?
,
SWIG Generated Java APIs:
public class Test {
public static String new_SWIGArrayUtility(int nelements) {
return TestJNI.new_SWIGArrayUtility(nelements);
}
public static void delete_SWIGArrayUtility(String ary) {
TestJNI.delete_SWIGArrayUtility(ary);
}
public static char SWIGArrayUtility_getitem(String ary, int index) {
return TestJNI.SWIGArrayUtility_getitem(ary, index);
}
public static void SWIGArrayUtility_setitem(String ary, int index, char value) {
TestJNI.SWIGArrayUtility_setitem(ary, index, value);
}
public static int numFoo() {
return TestJNI.numFoo();
}
public static String getCharArray() {
return TestJNI.getCharArray();
}
public static char[] getCharArrayImpl() {
final int num = numFoo();
char ret[] = new char[num];
String result = getCharArray();
System.out.println("result=" + result);
for (int i = 0; i < num; ++i) {
ret[i] = SWIGArrayUtility_getitem(result, i);
System.out.println("ret[" + i + "]=" + ret[i]);
}
return ret;
}
}
Inspired by Raymond Chen's post, say you have a 4x4 two dimensional array, write a function that rotates it 90 degrees. Raymond links to a solution in pseudo code, but I'd like to see some real world stuff.
[1][2][3][4]
[5][6][7][8]
[9][0][1][2]
[3][4][5][6]
Becomes:
[3][9][5][1]
[4][0][6][2]
[5][1][7][3]
[6][2][8][4]
Update: Nick's answer is the most straightforward, but is there a way to do it better than n^2? What if the matrix was 10000x10000?
In a ruby on rails app, I build an array of Project Names and project id values, but want to truncate the length of the names. Current code is:
names = active_projects.collect {|proj| [proj.name, proj.id]}
I have tried to add a truncate function to the block, but am getting undefined method for class error.
Thanks in advance - I just cannot wrap my head around this yet.