linkedliststack not longer requires T to be comparable#288
Open
oliverdain wants to merge 1 commit into
Open
Conversation
has all methods except `Contains`, `IndexOf`, and `Sort` so `T` no longer has to be a comparable. Then I changed `linkedliststack` to be based on `SimpleList` instead of `List` so it no longer requires `T` to be a comparable.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



I had a use case for a stack with a type that's not comparable. I noticed that none of the methods on
linkedliststack.Stackactually requiresTto be comparable. It seems the requirement stems from the fact thatlinkedliststackis based onsinglylinkedlistwhich has 3 methods (IndexOf,Contains, andSort) whichStackdoesn't use.This refactors
singlylinkedlist.Listinto asinglylinkedlist.SimpleListwhich has aT anygeneric type. And thensinglylinkedlist.ListembedsSimpleListand adds those 3 methods. ThenStackis based on aSimpleList[T any]and it no longer requires comparable.If you like the general approach here I suspect you'd want additional changes like an interface for simple lists, maybe all stacks no longer require comparable, etc. I wanted to get some early feedback to see if you're on board with this direction and, if so, where you'd want to take this.