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

Ports-Elise #3

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

Ports-Elise #3

wants to merge 5 commits into from

Conversation

ChubbyCub
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very fast and nicely done. Take a look at my comments and let me know if you have any questions. Mostly small things I noticed.

# Time Complexity: O(1)
# Space Complexity: O(1)
def add_first(value)
temp_node = @head

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this temp node?

# Space Complexity: O(1)
def find_max
if @head == nil
return @head

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return nil?

# Space Complexity: O(1)
def length
length = 0
if @head == nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this if statement?

# method to delete the first node found with specified value
# Time Complexity: O(n)
# Space Complexity: O(1)
def delete(value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done

# returns the value at the middle element in the singly linked list
# Time Complexity: O(n)
# Space Complexity: O(1)
def find_middle_value

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done, you didn't even use length!


temp_node = @head
idx = 0
while temp_node != nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use the method to get at an index here.

# returns true if a cycle is found, false otherwise.
# Time Complexity: O(n)
# Space Complexity: O(1)
def has_cycle

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nicely done, classic solution.

# method that inserts a given value as a new last node in the linked list
# Time Complexity: O(n)
# Space Complexity: O(1)
def add_last(value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding an instance variable @tail which refers to the last node in a linked list make this method easier or more efficient?

def add_last(value)
raise NotImplementedError
temp_node = @head
while temp_node != nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these types of loops could you instead do until temp_node.next.nil?

# list is sorted in ascending order
# Time Complexity:
# Space Complexity
def insert_ascending(value)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if you inserted a node which was less than the head of a long list.

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.

2 participants