Removing values from an array [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Is there any simple way to remove values from an array, and then move all the other values up into their positions, i.e. a bit like bit shifting?
For instance let's say I have an array
a[5] = {0x01,0x02,0x03,0x04,0x05};
and I would like to remove the first two values and shift the rest so that the array then becomes:
a[5]= {0x03,0x04,0x05,0x00,0x00};
Is there any easy way to do this without having to create a new array and use a for loop to transfer all the values after a[1]?

I'm not sure what language do you use, but general idea might be this
for(i=0; i<(5-2); i++){
a[i] = a[i+2];
}
a[3] = a[4] = 0;
So you don't need a copy of array, you can just shift values in existing one.

Related

Can't find how to extract part of an array using only the index path number. (swift) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have what I believe to be a very simple question but for some reason, I can't find an answer to it anywhere. Say I have an array:
var array = ["Apples","Dogs","Monkeys","Cats","Apples"]
With this array, I want to print the data "Monkeys"; how would I print the data "Monkeys" using only the known index number (3)?
I tried this code below, but it only returned the number 3, not the data at index number 3.
print(array.index(after: 2))
Thanks in advance, hope it's simple.
The index of an array is sort of like the address to the data. So when you ask to find the index of the array after number 2, you're just asking for the next valid address, not the data inside that address.
If you want to actually find the data after index number 2, you could do this:
print(array[2 + 1])
or
let index = 2
print(array[index + 1])
either way, using the brackets tells the code that you actually want to take a look inside that "address".
Lastly, it's important to note that arrays start counting at 0, not 1. So if you're looking to extract "Monkeys" from array, you want to look at array[2] not array[3].

finding the biggest value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
PLEASE NOTE: I am not looking for code, but for a way how to solve this problem.
My input is world that looks like this:
The problem is, i have to find the biggest number, without using OWN variables I could declare myself, and I'm only allowed to use turnLeft(), turnRight(), move(), isLeft/Right/FrontClear(), getNumber() and putNumber() functions to move < around the world.
Could you please give me a 'verbal solution' or a hint how to do such thing?
While you cannot use any variable, note that you do have available memory (getNumber() and putNumber()). For instance, you could think about leaving a mark in positions you have already been to implement some kind of flood fill.
Further, you can fill the floor with the biggest number you have seen yet. Basically, encoding your own state in the floor.
Important questions:
Is the configuration of the maze always fixed?
Is the range of possible numbers in the floor fixed to a reasonable range (e.g. digits 1-9)?

Count a 2D array within a range [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a map that I want to separately count the patterns of different numbers.
Without VB, I want to be able to create a dynamic counter that will be able to count the patterns of numbers.
For example:
I want to count how many times, even if it overlaps that this pattern occurs in the map
2 2
2 2
Counting I can see the pattern occurs six times but I'm struggling to create a simple array formula that will be able to do so
I've been told of success with and IF function with nested AND functions so I know it can be done without VB.
Use the formula
=COUNTIFS(A1:E15,2,B1:F15,2)
notice how the two areas are adjacent - one column offset from each other.
You can extend this to find two-by-two regions:
=COUNTIFS(A1:E14,2,B1:F14,2,A2:E15,2,B2:F15,2)
just be very careful about how the different ranges are offset.
An alternative way to write this which, I suspect, will be more efficient for large ranges is:
=SUMPRODUCT((A1:E14=2)*(B1:F14=2)*(A2:E15=2)*(B2:F15=2))

Design hash table with O(n) traversal, where n is number of elements [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Design hash table with following operations you are given with a good hashing function..:
insert() –O(1)
find()-O(1)
delete()-O(1)
traverse()-O(n)
As you insert elements into the hash table, you also add the elements to a linked list. When you are asked to traverse the hash table, iterate over the linked list.

Interview Q- product of all elements in array without the current element [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I recently came across an interview question and was wondering what could be the solution. Any ideas to solve it are greatly appreciated.
Given an array A[N] containing N numbers. Create an array Output[N] where Output[i] is equal to the product of all the elements of A[N] except A[i].
For example Output[0] is the product of A1 to A[N-1] and Output1 is the product of A[0] and from A[2] to A[N-1].
Do this without using the division operator. Do it in O(n).
Tip: do two iterations over the array - on the first one put in each cell the product of all preceding elements and on the second one multiply this by the product of all succeding elements.

Resources