potzko
potzko
Explore posts from servers
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
it looks neat, but I think ill stick to the explicit definitions everywhere as im only going to implement like 5-6 trees I think
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
actually no its not working how I think it works lol
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
ah now I think I get it
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
is internal for optimization or visibility?
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
and then I can acceess it
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
oh I can just add the accessibility thing to my interface
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
I see, thenks a lot, ill get to implementing some trees then 🙂
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
and have then there is no need to cast outside it
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
ah I should cast once, inside my SimpleTreeNode class
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
so I have to cast it first?
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
oh oops ty 🙂
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
I have the Node implementing the TreeNode as normal without the GetMin/GetMax:
public class SimpleTreeNode<T> : ITreeNode<T, SimpleTreeNode<T>> where T : IComparable<T>
...
public class SimpleTreeNode<T> : ITreeNode<T, SimpleTreeNode<T>> where T : IComparable<T>
...
and then when I try to use it
class SimpleTree<T> : ITree<T, SimpleTreeNode<T>, SimpleTree<T>>
where T : IComparable<T>
{
SimpleTreeNode<T>? root;

public T? GetMax()
{
if (this.root == null) {return default(T);}
return this.GetRoot()!.GetMax();
}
}
class SimpleTree<T> : ITree<T, SimpleTreeNode<T>, SimpleTree<T>>
where T : IComparable<T>
{
SimpleTreeNode<T>? root;

public T? GetMax()
{
if (this.root == null) {return default(T);}
return this.GetRoot()!.GetMax();
}
}
I get
'SimpleTreeNode<T>' does not contain a definition for 'GetMax' and no accessible extension method 'GetMax' accepting a first argument of type 'SimpleTreeNode<T>' could be found (are you missing a using directive or an assembly reference?)
'SimpleTreeNode<T>' does not contain a definition for 'GetMax' and no accessible extension method 'GetMax' accepting a first argument of type 'SimpleTreeNode<T>' could be found (are you missing a using directive or an assembly reference?)
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
why is that? can it not just use the ones I wrote for the interface?
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
when I write my tree it still asks me to implement them
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
in my Itreenode I implemented a generic search min/max functions:
public interface ITreeNode<T, NodeType>
where T : IComparable<T>
where NodeType : ITreeNode<T, NodeType>
{
T GetValue();
NodeType? GetLeft();
NodeType? GetRight();
T GetMax() {
ITreeNode<T, NodeType> tmp = this;
while (tmp.GetRight != null) {
tmp = tmp.GetRight()!;
}
return tmp.GetValue();
}
T GetMin() {
ITreeNode<T, NodeType> tmp = this;
while (tmp.GetLeft != null) {
tmp = tmp.GetLeft()!;
}
return tmp.GetValue();
}
}
public interface ITreeNode<T, NodeType>
where T : IComparable<T>
where NodeType : ITreeNode<T, NodeType>
{
T GetValue();
NodeType? GetLeft();
NodeType? GetRight();
T GetMax() {
ITreeNode<T, NodeType> tmp = this;
while (tmp.GetRight != null) {
tmp = tmp.GetRight()!;
}
return tmp.GetValue();
}
T GetMin() {
ITreeNode<T, NodeType> tmp = this;
while (tmp.GetLeft != null) {
tmp = tmp.GetLeft()!;
}
return tmp.GetValue();
}
}
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
one last question if you don't mind
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
I see
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
only me writing the code lol
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
maybe I can do some covariants but I don't think I will do em
75 replies
CC#
Created by potzko on 3/9/2024 in #help
help with generic interface
so you can quicly cast from one to another
75 replies