C
C#3y 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
cathei3y ago
$code
MODiX
MODiX3y 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
cathei3y ago
What is Node here, are you doing linked list not List<T>?
Enigma
EnigmaOP3y 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
cathei3y ago
It should be backtick ` not ‘
Enigma
EnigmaOP3y 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
cathei3y ago
Yay. and what is “not working” here Shouldn’t you update PartyList?
Enigma
EnigmaOP3y 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
cathei3y ago
By the while condition the temp is always null after loop
Enigma
EnigmaOP3y ago
the party is just not created are u here?
cathei
cathei3y ago
Like I said you should add node to PartyList Either head or tail
Enigma
EnigmaOP3y ago
wdym node node is the type of thing Node<party> is a list of parties
cathei
cathei3y ago
So you should add your newly created party node
Enigma
EnigmaOP3y ago
like Partylist = Partylist(Partylist,minmax) or something of the following
cathei
cathei3y ago
Basically, but make sure you don’t lose your link to another node
Enigma
EnigmaOP3y 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
cathei3y ago
Because temp is null after while loop
Enigma
EnigmaOP3y ago
I see So i dont really get what should i change
cathei
cathei3y ago
Partylist = new Node<Party>(minmax, Partylist);
Partylist = new Node<Party>(minmax, Partylist);
Try this instead
Enigma
EnigmaOP3y ago
Thanks
Accord
Accord3y 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.

Did you find this page helpful?