15,614,766 members
See more:
I'm practicing programming in java with lists, because in a while this exam. i can't solve 3 methods

1st: Write a method, belonging to a hypothetical list of numbers, which concatenates the L2 list passed as an argument to the end of the current list.

2nd: Write a method, belonging to a hypothetical list of numbers, which searches for an element and returns a new list containing the numbers corresponding to the position in which the element appears in the given list. For example if L is 1 -> 15 -> 1 -> 9 -> 8 -> 1 and the element to search is 1, then the method returns the list of positions where 1 is present in the list L. The returned list, in this case is: 1 -> 3 -> 6 (I have separated 2 methods one, "search" and the other "modify") Here I wrote:

What I have tried:

1st method I wrote:
Java
```public void concatenazione(Lista L,Lista L2) {
}
}
```

2nd method I wrote:
Java
```public int ricerca(int ricerca) {
int i=0;
if(p.getElemento()==ricerca) {
System.out.print(i++);
}
i++;
}
return i++;
}
```

```public void modificare(Nodo L) {
int disparo=0;
if(L.getElemento()/2==1) {
L.setElemento(disparo);
L.setElemento(disparo);
}
}
}
```
Posted
Updated 23-Aug-22 0:33am

## Solution 1

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 2

You are asked to write `2` methods. Why are you providing 3 ones?

Quote:
public void concatenazione(Lista L,Lista L2) {
}
}

This should be more similar to
Java
```public void concatenazione(Lista L2)
{

while (q != null)
{
// here you should create a new node (a duplicate of q) say 'qcopy'
p = qcopy;
}
}```

The second method should, in just one list traversing, produce the expected output. That is, while traversing the input list, if the item is equal to the passed one, than its postion should be added to the output list.