C
C#2y ago
Enigma

❔ 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
cathei
cathei2y ago
$code
MODiX
MODiX2y ago
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/
cathei
cathei2y ago
What is Node here, are you doing linked list not List<T>?
Enigma
EnigmaOP2y ago
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); } '''
cathei
cathei2y ago
It should be backtick ` not ‘
Enigma
EnigmaOP2y ago
// 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);
}

// 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);
}

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
cathei
cathei2y ago
Yay. and what is “not working” here Shouldn’t you update PartyList?
Enigma
EnigmaOP2y ago
Partylist is simply the list off all parties class World { private string name; private Node<Party> Partylist; this are the properties of world
cathei
cathei2y ago
By the while condition the temp is always null after loop
Enigma
EnigmaOP2y ago
the party is just not created are u here?
cathei
cathei2y ago
Like I said you should add node to PartyList Either head or tail
Enigma
EnigmaOP2y ago
wdym node node is the type of thing Node<party> is a list of parties
cathei
cathei2y ago
So you should add your newly created party node
Enigma
EnigmaOP2y ago
like Partylist = Partylist(Partylist,minmax) or something of the following
cathei
cathei2y ago
Basically, but make sure you don’t lose your link to another node
Enigma
EnigmaOP2y ago
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
cathei
cathei2y ago
Because temp is null after while loop
Enigma
EnigmaOP2y ago
I see So i dont really get what should i change
cathei
cathei2y ago
Partylist = new Node<Party>(minmax, Partylist);
Partylist = new Node<Party>(minmax, Partylist);
Try this instead
Enigma
EnigmaOP2y ago
Thanks
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server