Skip to content

Branches, C. Gutierrez#22

Open
CEsGutierrez wants to merge 2 commits intoAda-C12:masterfrom
CEsGutierrez:master
Open

Branches, C. Gutierrez#22
CEsGutierrez wants to merge 2 commits intoAda-C12:masterfrom
CEsGutierrez:master

Conversation

@CEsGutierrez
Copy link

No description provided.

@CEsGutierrez
Copy link
Author

Added tests for advanced exercises

@CEsGutierrez CEsGutierrez changed the title basic functionality of linked lists Branches, C. Gutierrez Feb 18, 2020
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.

Nice work, you hit all the learning goals here. Well done. Take a look at my comments and let me know if you have questions. Your methods pretty much all work, but some could use a bit of refactoring to simplify the methods a bit.

class Node
attr_reader :data
attr_accessor :next
attr_accessor :prev

Choose a reason for hiding this comment

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

Nice you're implementing a Doubly Linked List!

end
end

def get_first

Choose a reason for hiding this comment

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

👍

end
end

def length

Choose a reason for hiding this comment

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

👍

Comment on lines +69 to +73
elsif current.next == nil
current.next = temp
temp.prev = current
return
end

Choose a reason for hiding this comment

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

Do you need this elsif?


end

def get_last

Choose a reason for hiding this comment

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

👍

# checks if the linked list has a cycle. A cycle exists if any node in the
# linked list links to a node already visited.
# returns true if a cycle is found, false otherwise.
def has_cycle

Choose a reason for hiding this comment

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

Nice approach, a bit higher space complexity, but it definitely works!

# Additional Exercises
# returns the value in the first node
# returns nil if the list is empty
def get_first

Choose a reason for hiding this comment

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

👍

end

# method that inserts a given value as a new last node in the linked list
def add_last(value)

Choose a reason for hiding this comment

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

👍


# method that returns the value of the last node in the linked list
# returns nil if the linked list is empty
def get_last

Choose a reason for hiding this comment

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

👍


# method to insert a new node with specific data value, assuming the linked
# list is sorted in ascending order
def insert_ascending(value)

Choose a reason for hiding this comment

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

👍

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