Skip to content

Conversation

@mephistophele-s
Copy link

Adding examples on Swift.

Copy link

@GreatAndPowerfulKing GreatAndPowerfulKing left a 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).

Copy link

@GYFK GYFK left a 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

Copy link

@Gagnant Gagnant left a 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 be private or fileprivate inner class
  • first returning type must be T
  • last returning type must be T
  • func remove(node: T) -> T? must be func remove(value: T) -> T?
  • func nodeAt(index: Int) -> Node<T>? must be func valueAt(index: Int) -> T?
  • LinkedList must conforms to Collection protocol or MutableCollection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants