-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding examples on Swift. #16
base: master
Are you sure you want to change the base?
Adding examples on Swift. #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, I think that LinkedList
should be generic.
Also, I suppose you shouldn’t provide even internal access to Node
class. I would declare it as private inner class of LinkedList
. first
and last
computed properties should return not Node?
, but generic T?
(node?.data
). And func node(at index: Int) -> Node?
should be replaced with func value(at index: Int) -> T?
.
And the last one, providing methods for printing isn’t a good style. Much better would be to make your LinkedList
to conform CustomStringConvertible
protocol and then print it like print(list)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anastasiaSTR I will suggest using MacOS as for the target platform. It should shorten build time and besides you are not using any platform specific functionality.
Then, you should consider conforming to some of the related protocols such as, for example, Collection
protocol.
upd: even MutableCollection
as suggested by @GreatAndPowerfulKing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned by @GreatAndPowerfulKing and @GYFK , please check that your LinkedList
conforms to the next points:
-
Node
must beprivate
orfileprivate
inner class -
first
returning type must beT
-
last
returning type must beT
-
func remove(node: T) -> T?
must befunc remove(value: T) -> T?
-
func nodeAt(index: Int) -> Node<T>?
must befunc valueAt(index: Int) -> T?
-
LinkedList
must conforms toCollection
protocol orMutableCollection
Adding examples on Swift.