❔ help with creating a list of objects from other lists
yo, i have a project on nodes (a list of lists) and on the the functions i need to create a new party (the second tier) of all the character (first tier) which have the highest level in each party, how would i get around doing this, i have some code but its currently not working, this is the code, i would love some help, thank you public void SpecMinMax() //10
{
Node<Party> temp = Partylist;
Party minmax = new Party("minmax");
while (temp != null)
{
minmax.AddChar(temp.GetValue().FindStrongestChar());
temp = temp.GetNext();
}
temp = new Node<Party>(minmax, temp);
}
21 Replies
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/What is
Node
here, are you doing linked list not List<T>
?i belive node is a linked list, with value and next, i just work on an alternate version of that with my school
'''cs
// public void SpecMinMax() //10
{
Node<Party> temp = Partylist;
Party minmax = new Party("minmax");
while (temp != null)
{
minmax.AddChar(temp.GetValue().FindStrongestChar());
temp = temp.GetNext();
}
temp = new Node<Party>(minmax, temp);
}
'''
It should be backtick ` not ‘
the goal of the action is to create a new party minmax
which concludes of the strongest character from each party
if u need any clarity with the code lmk
Yay. and what is “not working” here
Shouldn’t you update PartyList?
Partylist is simply the list off all parties
class World
{
private string name;
private Node<Party> Partylist;
this are the properties of world
By the while condition the
temp
is always null after loopthe party is just not created
are u here?
Like I said you should add node to PartyList
Either head or tail
wdym node
node is the type of thing
Node<party> is a list of parties
So you should add your newly created party node
like Partylist = Partylist(Partylist,minmax)
or something of the following
Basically, but make sure you don’t lose your link to another node
thanks
i changed my code to this
public void SpecMinMax() //10
{
Node<Party> temp = Partylist;
Party minmax = new Party("minmax");
while (temp != null)
{
minmax.AddChar(temp.GetValue().FindStrongestChar());
temp = temp.GetNext();
}
temp = new Node<Party>(minmax, temp);
Partylist = temp;
and now once i use the action it only keeps the minmax party
Because temp is null after while loop
I see
So i dont really get what should i change
Try this instead
Thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.