arrays

Objects with arguments and array

Is there a way in C++ where an objects has argument added upon it, with an array such as: int x = 1; int y = 2; Object myObject( x, y )[5]; // does not work I was hoping that I could put arguments into the object, while creating an array of 5 of these objects, does anyone know how? and is there a bteter way? ...

Performance: vector of classes or a class containing vectors

I have a class containing a number of double values. This is stored in a vector where the indices for the classes are important (they are referenced from elsewhere). The class looks something like this: Vector of classes class A { double count; double val; double sumA; double sumB; vector<double> sumVectorC; vector<double>...

Should I use char** argv or char* argv[] in C?

I'm just learning C and was wondering which one of these I should use in my main method. Is there any difference? Edit: So which one is more common to use? ...

Convert List<T> to object[]

I am looking for a one liner that transforms List<T> into object[]. It's one liner, so I am not interesting in solutions such as foreach, or for... Any takers? Hint: No, both List<T>.ToArray() and List<T>.ToArray<object>() don't work. Edit: Why List<T>.ToArray<object>() doesn't work? Because it can't compile. ...

[Java] What is wrong with this array declaration?

All right so I have agonized over this code for the past hour or so. This is the code for the class in question. public DistanceProject(String costs, String firstString,String secondString) { Scanner scan = new Scanner(costs); copyCost = scan.nextInt(); replaceCost = scan.nextInt(); deleteCost = s...

What C compilers have pointer subtraction underflows?

So, as I learned from Michael Burr's comments to this answer, the C standard doesn't support integer subtraction from pointers past the first element in an array (which I suppose includes any allocated memory). From section 6.5.6 of the combined C99 + TC1 + TC2 (pdf): If both the pointer operand and the result point to elements of t...

c# array function argument pass one dimension

Let say I got this function : void int Calculate(double[] array) {} And in my main I got this array: double[,] myArray = new double[3,3]; How can I call Calculate(...) ? I try (that's don't compile) : double[] mySingleArray = myArray[0]; What I want to avoid is unnecessary loop (for). I declare a regular array, but if a jagge...

Why @($null) is $false, but @($null, $null) is $true?

Curious, what is the idea behind this: @() -as [bool] # False @($null) -as [bool] # False @($null, $null) -as [bool] # True I would expect either False/True/True or False/False/False, but not False/False/True. ...

Using arrays with recursion

Now that I am using recursion to calcuate the sum of numbers, I want to do something slightly different. The following is my code that will sum the numbers 1,2,3,4,5. How would I modify my code to place the numbers 1, 2, 3, 4, 5 into an array and then use it in the recursion method? I have tried so many different attempts and I am app...

How can I efficiently extract repeated elements in a Ruby array?

I have an array like [1,1,1,2,4,6,3,3] and I would like to get the list of repeated elements, in this case [1,3]. I wrote this: my_array.select{|obj|my_array.count(obj)>1}.uniq But it is tragically inefficient (o(n²)). Do you have a better idea? If possible concise. Thanks ...

jquery delete array from the textarea

How can I use jQuery to delete the text in the textarea that gets from the input_one when it not checked (one_1 one_3 one_4) ,and when it checked add it into textarea again? The code is below: <div id="input_one"> <input type="checkbox" checked value="one"> <input type="checkbox" checked value="one_1"> <input type="checkbox" valu...

array offset calculations in multi dimensional array (column vs row major)

A textbook I recently read discussed row major & column major arrays. The book primarily focused on 1 and 2 dimensional arrays but didn't really discuss 3 dimensional arrays. I'm looking for some good examples to help solidify my understanding of addressing an element within a multi-dimensional array using row major & column major arra...

How can i compare (Jagged Arrays, Arrays, ArrayList)'s performance?

Is there any performance counter? Or i really get result like that: Jagged Arrays: 2000 ms Arrays : 3000 ms ArrayList : 4000 ms How can i code method to get performance result? ...

Question about array shallow copy in C#

Just to make sure I'm understanding shallow copies of reference types correctly and that I'm not constructing a huge memory leak here: // Adds text to the beginning of the log RTB // Also keeps the log RTB trimmed to 100 lines var lines = new string[rtbLog.Lines.Length + 1]; lines[0] = "text"; Array.Copy(rtbLog.Lines, 0, lines, 1, rtbLo...

How similar is an std::vector to a raw array in C++?

I'm writing a hangman game. I'm having a logic fail, both with myself and my game logic. Char guess (the letter the person guessed) isn't being added into the correct memory slot of the vector guessArray. Assume that word is an inputted word by the user. I assume this would work if guessArray were a raw array. Is there some reason this...

php array_merge without erasing values?

Problem: by default, PHP array_merge works like this ... it will overwrite a non-blank value with a blank value. $foobar = Array('firstname'=>'peter','age'=>'32','nation'=>''); $feebar = Array('firstname' => '','lastname' => 'griffin', age =>'33','nation'=>'usa'); print_r(array_merge($foobar,$feebar)); /* Array ( [first...

Does Index of Array Exist

I've inherited some code at work that has a really bad smell. I'm hoping to find the most painless solution possible. Is there a way to check if some arbitrary number is a valid element in an array? Example - I need to check if array[25] exists. Preferably I would prefer to do this without doing a foreach() through the array to found...

ruby loop refactor

Hi All, I have a loop that looks like this def slow_loop(array) array.each_with_index do |item, i| next_item = array[i+1] if next_item && item.attribute == next_item.attribute do_something_with(next_item) end end end aside from changing the way do_something_with is called, how can i make this perform better? thx, -C...

Too many elements in an array!

Sorry if this is a noob question :( . Piece of C code. int array[5]; int cnt; for(cnt = 0; cnt <= 10; cnt+=1) { array[cnt] = cnt; } Should give an error, right? No! Works fine! But why is that? It seems that -in the first line- an array of more than the double size (11) is defined. You can even access array[5 to 10] later on....

How to set an Arrays internal pointer to a specific position? PHP/XML

Im trying to build a little site using XML instead of a database. I would like to build a next and prev button which will work relative to the content I have displayed. I found the php function next() and prev() as well as current() but I do not know how to set the pointer to a specific position to be able to navigate relative to the ...