Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Adding examples on Swift. #16

wants to merge 2 commits into from

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