An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one index. All the elements of an array are stored adjacent to each other.
-2
votes
0answers
64 views
Java Multi-Client Chat Application - Sending messages problem [closed]
My problem is, I can still send messages between Clients(Client-to-Client) but after sending two or three times, messages are no more displayed to the recipient.
So basically whenever the Client wish ...
0
votes
1answer
31 views
2D Array: Retrieve the “Left” Item
I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]
One of the things that I want to accomplish is to be able to retrieve ...
3
votes
1answer
55 views
Better Javascript to find unique values in an array
My objective is to make an array of unique keys from a list of objects. Example:
Input:
var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}]
Output:
[ "a", "b", "c" ]
Current approach:
var ...
2
votes
1answer
104 views
Too slow two strings comparer
I have 2 strings for example:
abcabc and bcabca
or
aaaabb and abaaba
I checked that second string is the same or not like first string but shifted.
bcabca = ..abca + bc...
Here is code it works ...
4
votes
1answer
61 views
Array find min value with user-defined comparison compare function
My user defined comparison compare function is defined with an array:
$boardkey_to_values=Array(19=>2601248,23=>2601248,39=>2603445,
...
1
vote
2answers
56 views
Looking For a More Efficient/Elegant Way To Write a MySQL Query
I'm querying a MySQL database and displaying the info in order of timestamp (DESC). Essentially, I'm grabbing the last record in the database, displaying it's date and year as the header of it's ...
1
vote
3answers
94 views
Reverse a string without <string.h> header function
I'm learning C from K.N. King book and just arrive at a question to reverse the words in a sentence.
Here is the output:
Enter a sentence: you can cage a swallow can't you?
Reversal of sentence: ...
0
votes
1answer
131 views
Please critique my C++ Deck class
I have recently finished creating my own Deck class for my Poker game. It works the way I want it to, but I would like to know if I can make it better and/or more efficient. Here's what I have:
...
3
votes
1answer
60 views
Matching element of arrays on a condition
if node[i] and node[i+1] are present in the neighbor[i], then store the 'i' position of node and print the 'i' value of node.
this is also done by reversing the node array(only) and same type of ...
2
votes
2answers
101 views
Calculating and displaying number statistics
I'm writing a program which takes individual int inputs from the user and then outputs some details on the numbers (average, min, max and how many).
Input.readInt() is a method I made which simply ...
3
votes
3answers
76 views
Most efficient way to iterate through arrays/can I use .times method in place of while method?
I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the .times method in place of the while code blocks to increase ...
3
votes
1answer
95 views
Magic Square in C (Beginner)
Still teaching myself C out of KN King's C Programming: Modern Approach. Actually pretty excited I go this problem solved in under 2 hours haha. I asked this over on Stack Overflow and it was ...
3
votes
1answer
44 views
Code to find the proper index comparing 3 values for max one
I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value.
I.e.
if array[i + 1][j + 1] has the largest value among the 3 ...
3
votes
1answer
94 views
Rails: Retrieve all parents, all possible children, sorted and with their “depth”
I have a model section with a column parent_id - the only thing identifying a parent/child relationship. I wrote a helper method to output all sections, all their possible subsections and include ...
2
votes
3answers
104 views
Searching item in array
I have a program that calculates some values and saves them to an array. Before save a value, program checks if there is already an identical value in array:
string someData = GetData();
bool ...
3
votes
3answers
103 views
Cached empty collections
I often find myself in need to create empty collections. One of those days several years ago, I wrote something like the following to address that:
public static class Array<T>
{
// As a ...
1
vote
1answer
84 views
first non-repeated character in a string in c
Write an efficient function to find the first non-repeated character in a string. For example, the first non-repeated character in "total" is 'o' and the first non-repeated character in "teeter" is ...
1
vote
0answers
24 views
NSArray and NSNumber-int conversions
I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line.
However, when text ...
0
votes
3answers
60 views
Given an 2D array which is row and column wise sorted. What is the efficient way to search for an element?
For example, given a 2D array (a matrix)
{{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}}
What are the solutions to find a number? say 6.
Here's the code I tried using Binary search method -
(code ...
3
votes
4answers
217 views
How make array search more efficient in python?
Here is Python code written to perform the following operations:
Find each occurrence of a three-letter sequence in a character array (e.g. a sequence such as ('a','b','c')), including overlapping ...
1
vote
1answer
73 views
Multiple jQuery events on one element with different functions and target selectors
According to this two questions: [1] and [2]
I need a way to combine these two methods of handling the event attachment in jQuery.
$('selector').on({
mouseenter: function() {},
mouseleave: ...
2
votes
1answer
142 views
Ranking and sorting on Array/List
My apology, I am quite new to posting a question in this forum.
I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ...
1
vote
1answer
55 views
Optimize nested enumerate blocks?
Well,
i have 3 nested NSEnumeration loops, used to get the textfields of a custom cell, in a custom table in a custom view in a controller...
How can i change this code to make more readable and more ...
0
votes
1answer
140 views
Best way convert byte array to hex string in C#
I want to find a prettier version of this method:
public static string ByteArrayToString(byte[] byteArray)
{
var hex = new StringBuilder(byteArray.Length * 2);
foreach (var b in byteArray)
...
4
votes
2answers
95 views
Counting letters program. Notation and optimisation help
I am writing a program in C running on UNIX which counts the number of each letters in a input text file. For a file like this:
The cat sat on the green mat
The output would be like this:
The ...
0
votes
1answer
50 views
JSON get Array in Array [closed]
I need to generate JSON array in array data.
I am able to get data from first array, however not able to get data from child array.
For example :-
[
{
"id":"2012"
"month":
[
{ ...
1
vote
0answers
162 views
App engine Java: Sum difference two arrays - How to improve performance?
I have a function in App Engine java where I compare two patterns stored in an int array.
Below is the code:
public static int patternMatch(int [] pattern1, int [] pattern2, int range) {
int ...
1
vote
2answers
173 views
Please help me debug this little C program on dynamic two-dimensional array?
I am a newbie here. I have written a little C program, which is to create a two-dimensional matrix. Here is the code:
#include <stdio.h>
#include <stdlib.h>
int **CreatMatrix(int ...
1
vote
1answer
100 views
C arrays and loops optimization
I am writing a program for learning purposes that takes an input of a file structured similarly to:
13,22,13,14,31,22, 3, 1,12,10
11, 4,23, 7, 5, 1, 9,33,11,10
40,19,17,23, 2,43,35,21, 4,34
...
4
votes
1answer
132 views
Optimizing Python / Numpy Code
So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy.
I've written a pure numpy version of the actual mean shifting per pixel (which I ...
0
votes
1answer
60 views
help review array of object code [closed]
public class DoubleMatrix
{
private double[][] doubMatrix;
public DoubleMatrix(int row, int col)
{
if(row > 0 && col > 0)
{
makeDoubMatrix(row,col);
}
...
1
vote
2answers
62 views
Request for help to tidy up code involving arrays and loops
I posted the following code on here a few days ago:
public class Practical4_Assessed
{
public static void main(String[] args)
{
Random numberGenerator = new Random();
int[] ...
0
votes
2answers
63 views
add Matrix method review
package homework3;
public class DoubleMatrix
{
private double[][] doubMatrix;
public DoubleMatrix()
{
int row;
int col;
if(row > 0 && col > 0)
...
0
votes
1answer
51 views
Compare Arrays in Dice game [closed]
I found an open source project that has a few bugs (I have fixed a couple so far) but this one has me stumped. The issue that I am trying to solve... If I have 3 sets of pairs (isThreePair) and it ...
4
votes
1answer
245 views
A blocking buffer manager to provide segments of a byte array
Since asynchronous operations (like Socket's Begin*-End* pairs and *Async methods) that use IOCP under the hood cause the byte array that you use as buffer to be pinned in the memory.
So if you ...
5
votes
1answer
79 views
Sparse Bitarray Class in Python (or rather frequently having contiguous elements with the same value)
Sparse is probably the wrong word - this is for encoding arrays of booleans where contiguous values tend to be the same. It'd be great to know a proper name for this data structure so I could read ...
4
votes
1answer
112 views
Partitioning Array
Problem: Given a randomly ordered array of n-elements, partition the
elements into two subsets such that elements <=x are in one subset and
elements > x are in the other subset.
one way to do this ...
4
votes
3answers
111 views
Is my code dealing with the presented problem the right way?
I finished this program to print a 2D array, I got the right output, but I'm not sure if I did what was being asked in the problem below.
My code to deal with the presented problem:
package ...
4
votes
3answers
265 views
A simple array-based Stack class in Java, what are my mistakes?
I have created a simple array-based Stack class with some methods like the actual Stack in Java.
I am testing this for mistakes, but since I am learning Java and my tests may not be as comprehensive ...
4
votes
2answers
202 views
A simple ArrayList class in Java, what are my mistakes?
I have created a simple ArrayList with some methods from the actual ArrayList in Java.
I am testing this for mistakes, but I am learning Java and my tests maybe are not comprehensive. So I decided to ...
2
votes
1answer
55 views
Implement numbering scheme like A,B,C… AA,AB,… AAA…, similar to converting a number to radix26
I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below
A
B
C
.
.
AA
...
0
votes
1answer
127 views
Am I doing this right? Merging 2 ordered source arrays into one destination array
My instructions were:
Add a merge() method to the OrdArray class in the orderedArray.java
program (Listing 2.4) so that you can merge two ordered source arrays
into an ordered destination ...
3
votes
1answer
110 views
C# Array Mutator Methods to mimic JavaScript Array Mutator Methods
Between .NET's built-in collection libraries and LINQ extension methods, I never have to use arrays. An unfortunate consequence of this is that I am probably less competent in working with this very ...
3
votes
1answer
403 views
Better way of handling data returned from fetch_assoc() (mysqli)
So I connected to the db, pull the data using fetch_assoc() (fetch_all(NUMB) is not available on the machine we are working with else this would be less of an issue). So I get the returned data and ...
2
votes
3answers
348 views
How to improve my stack implementation (uses array)?
Below is an implementation of a stack data structure using arrays. Please comment on the same. How can it be improved?
Specific improvements I am looking for:
Memory leaks
C++ style
Making code run ...
2
votes
2answers
137 views
Is this a good way to calculate the mode of a set of ints?
Today was my first day of Data Structures and Algorithms in C++. We used C# last semester and C++ for the intro class so to get us used to C++ again we had a simple assignment to write a program to ...
4
votes
2answers
648 views
Reading a line from a text file and splitting its contents
I have this kind of file structure
MALE:FooBar:32
FEMALE:BarFoo:23
Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>
try{
BufferedReader in = ...
5
votes
3answers
166 views
Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's
Assume a 2d [n][n] Matrix of 1's and 0's/ All the 1's in any row should come before 0's/The number of 1's in any row i should be atleast the no of 1's row (i+1). find a method and write a c program to ...
4
votes
1answer
651 views
Java 2d array nested loops
Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both ...
1
vote
0answers
323 views
Android - get int array from database Cursor
I find this code quite ugly, but in fact, I don't see any finest way to achieve the goal.
private static final String TABLE_NAME = "table_name";
private static final String[] allNeededColumns = ...