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 7 years ago.
Improve this question
I´m trying to implement a way to find all possible solutions to Pentominos of W, L and I with the help of DLX-Algorithm, or Algorithm-X of Knuth in a 5 x n rectangle.
My approach is to find all ways to insert a W into a 5 x 3 rectangle. I want to implement this first and then the full program.
So this is tons of stuff to read and to understand and I understood somehow how it works but I encountered a problem when looking at this part of the code given by my prof.
class Node // represents 1 element or header
{
Node C; // reference to column-header
Node L,R,U,D; // left, right, up, down
Node()
{
C=L=R=U=D=this; // supports circular lists
}
}
My question: How does the reference to C=...=this work? I know the difference between instance and local variables but I don't know how to understand the reference to "this" in the constructor. What does it do?
In this instruction
C=L=R=U=D=this;
thisrepresents the instance of the Node class that is being processed at runtime (dynamically): so it simply means that all your other Node variable will receieve reference to the current instance of Node that was being constructed.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
This is the main method from where I am trying to pass values to the skill class which accepts array. I do not want to give employee e1 all the skills but just s4, how can I do that so my code becomes logical and correct
You have different way to achieve this.
Taking into consideration the piece of code you showed above, the easiest way to do that which doesn't imply to add any additional method to the Employee class, is to create a new array of Skill while invoking setEmployeesSkills on e1, so your code will appear more or less like this:
e1.setEmployeesSkills(new Skill[]{s4});
Hope that is what you are looking for, otherwise please share more info and I will try to help you further.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I tried to search the internet but I didn't see it's been asked. So our lecturer told us, we must write our own linked-list from scratch. Inside the linkedlist have head and tail pointing at another when you add item. Suppose if inside I already add a working integer counter. My question is I have 2 option to check if the linkedlist is empty:
check the head is null
check the counter is 0
my question is which is better in term of efficiency? I know the checking is millisecond matter, but I want to know, in theory, which one got better advantage over another? Sorry I'm not taking Operating System, I not know much the theory.
If you're asking which has better performance, they'll be exactly the same. In both cases you're doing a field or property access followed by a numeric comparison against a constant value. (null is just 0 as a memory address.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
The thing is I need to create an unidimensional array that represents a certain number of objects.
Those objects are organized as shown in the picture.
Link
And I have to be able to tell wich one is conected to.
The number of objects is the only thing given.
Is there any algorithm of some sort to do this?
This sort of organization is often used to implement heaps in arrays: https://www.geeksforgeeks.org/array-representation-of-binary-heap/
You just put the objects into the array in level order (top 1 first, then the 2 from level 2, then the 4 from level 3, etc.).
Assuming 0-based indexing, then, the object in array[i] has children array[2*i+1] and array[2*i+2].
If your array starts at [1], then the object in array[i] has children array[2*i] and array[2*i+1]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Array<Body> bodies = new Array<Body>(world.getBodyCount());
world.getBodies();
for (Body body : bodies) {
update(body);
}
Okay, first you're allocating an Array and ensuring the backing array will fit world.getBodyCount(). So, if the existing number of bodies in your world is ten, the ArrayList will have enough memory allocated to store ten bodies initially, but all of these entries will be null.
Then you call world.getBodies(); but this has no access to the local variable bodies, it's definitely not static; therefore your Array is still left uninitialized!
The Array is empty when you come to the for loop, so it execues zero times; nothing gets updated. So; the real trick is you're not accessing the bodies contained within the world properly.
Does getBodies() return a List you should be using instead?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to show images upon clicking a button.
These images must come from an array so that i can easily add or delete images without having to edit all of my code.
However the compiler aborts my build and i have 2 errors.
public void showQuestion()
{
currentQuestion++;
imageNumber++;
if(currentQuestion == questions.length)
currentQuestion = 0;
if(imageNumber == myImageList.length)
imageNumber = 0;
questionView.setText(questions[currentQuestion]);
answerView.setText("");
answerText.setText("");
imagesview.setImageResource(myImageList[imageNumber]);
}
the first error is at imageNumber == myImageList.length, saying
Multiple markers at this line
length cannot be resolved or is not a field
myImageList cannot be resolved to a variable
the second error is on images view.setimageResource(myImageList[imageNumber]);
Multiple markers at this line
The type of the expression must be an array type but it resolved to ArrayList<Integer>
myImageList cannot be resolved to a variable
Edit:
The mistake i made was i overlooked that i was using an INT with the .length attribute. and a set instead of a .get!
Hope it helps
An ArrayList is of type list. Therefore .length should be .size() and myImageList[imageNumber] should be myImageList.get(imageNumber).