Skip to content

added merge() funtion and test cases - #43

Open
hemabhagnani wants to merge 6 commits into
codesankalp:masterfrom
hemabhagnani:hemabhagnani
Open

added merge() funtion and test cases#43
hemabhagnani wants to merge 6 commits into
codesankalp:masterfrom
hemabhagnani:hemabhagnani

Conversation

@hemabhagnani

Copy link
Copy Markdown

fixes #35

Comment thread dsalgo/linked_list.py Outdated

return head

def merge_linked_list(self, list2):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good Effort and pull request !
rename the function to sorted_merge.
Also in the parameter you are not taking two linked list head.
for example: user should be able to pass 2 linkedlist in the parameter to get the head of new sorted linkedlist.
so there is no use of self it should be declared explicitly because we want this as a linkedlist method.
@devkapilbansal you can also suggest something.

Comment thread dsalgo/linked_list.py Outdated
"""
:param: head - head of first linked list
:param: list2 - head of second linked list
return - return a new merged linked list

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

it should be return a new sorted merged list.

Comment thread dsalgo/linked_list.py
array = self.to_list()

linked_list = LinkedList()
for value in array:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

you can also reduce these steps but it's fine.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do I need to use a diff approach for merge() ?

@codesankalp

Copy link
Copy Markdown
Owner

@hemabhagnani this pull request looks good to me and will be ready to merge after mentioned changes.
Thanks!

@hemabhagnani

Copy link
Copy Markdown
Author

@codesankalp I'll do the suggested changes

@devkapilbansal

Copy link
Copy Markdown
Collaborator

@hemabhagnani are you working on this?

@hemabhagnani

Copy link
Copy Markdown
Author

Actually, I wanted to ask whether I have to change the approach of the merge() function apart from this I have done the requested changes.

Comment thread dsalgo/linked_list.py

def __repr__(self):
return "LinkedList({})".format((self.to_list()))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

define the sorted_merge function explicitly i.e. not in the class.
and also don't remove this function and use the self instead of list1.
so this is the final instructions:-

  • in the current sorted_merge function use self instead of list1.
  • define a new function sorted merge outside the class which takes two args list1 and list2 and returns merged linked list.

@devkapilbansal

Copy link
Copy Markdown
Collaborator

@codesankalp @17sushmita review it

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add function "merge()" in existing linked_list.py to perform merging of two given linked list.

3 participants