Not Yet Answered # Deleting Random Nodes

Drowzee 3 Narue 5,707 Discussion Starter heavyc Narue 5,707 Discussion Starter heavyc Narue 5,707

0

It would be easiest to check the list beginning to end to see if you have the value already, then not make the node if there's already one with that value.

0

Here is the basic idea behind what you're trying to do:

```
// Pseudocode
for ( i = first; i != last; i = next ( i ) ) {
for ( j = next ( i ); j != last; j = next ( j ) ) {
if ( i == j )
unlink ( j );
}
}
```

However, if your list is sorted then all you have to do is unlink one of two adjacent nodes that match.

0

Here is the basic idea behind what you're trying to do:

`// Pseudocode for ( i = first; i != last; i = next ( i ) ) { for ( j = next ( i ); j != last; j = next ( j ) ) { if ( i == j ) unlink ( j ); } }`

However, if your list is sorted then all you have to do is unlink one of two adjacent nodes that match.

but lets say that there is 10 numbers and they are random everytime would this still work or would i have to do something else.

0

>but lets say that there is 10 numbers and they are random everytime

You can say that, but you've already said it and I understood you completely the first time.

>would this still work

Yes, what I gave you was an inefficient algorithm that assumes nothing about the input sequence. So it will work with random numbers that potentially have duplicates. But you would have known that if you bothered to work through a sample sequence instead of coming back here to ask us without first thinking for yourself.

0

>but lets say that there is 10 numbers and they are random everytime

You can say that, but you've already said it and I understood you completely the first time.>would this still work

Yes, what I gave you was an inefficient algorithm that assumes nothing about the input sequence. So it will work with random numbers that potentially have duplicates. But you would have known that if you bothered to work through a sample sequence instead of coming back here to ask us without first thinking for yourself.

yes i understand what u mean about tryng it buut i did and i dont know what to plugg into those variables that you did .. if you could please help

0

I already gave you code for a linked list that gives you more than enough information to translate the pseudocode into valid C++. You won't learn anything if I just do it for you.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`