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

Add deque for JavaScript and typescript #267

Merged
merged 9 commits into from
Feb 4, 2023
Merged

Add deque for JavaScript and typescript #267

merged 9 commits into from
Feb 4, 2023

Conversation

zhuoqinyue
Copy link
Contributor

If this PR is related to coding or code translation, please fill out the checklist.

  • I've tested the code and ensured the outputs are the same as the outputs of reference codes.
  • I've checked the codes (formatting, comments, indentation, file header, etc) carefully.
  • The code does not rely on a particular environment or IDE and can be executed on a standard system (Win, macOS, Ubuntu).

@vercel
Copy link

vercel bot commented Jan 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
hello-algo ⬜️ Ignored (Inspect) Feb 1, 2023 at 7:32PM (UTC)

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Do js and ts doesn't provide built-in Deque? If so, please implement Deque using Linked List, because the popFront() is slow if implementing Deque using Array.

@zhuoqinyue
Copy link
Contributor Author

OK. I would change the implementation

@krahets
Copy link
Owner

krahets commented Jan 21, 2023

OK. I would change the implementation

Or implement it using circular array (a little more complicated than using linked list).

@krahets
Copy link
Owner

krahets commented Feb 1, 2023

Hi, we've added linkedlist_deque.java and you can refer to it.

I think you can directly use Array as the built-in deque in JS and TS, and add a comment to reveal O(n) time complexity for the addFirst() and pollFirst() methods.

1 similar comment
@krahets
Copy link
Owner

krahets commented Feb 1, 2023

Hi, we've added linkedlist_deque.java and you can refer to it.

I think you can directly use Array as the built-in deque in JS and TS, and add a comment to reveal O(n) time complexity for the addFirst() and pollFirst() methods.

@zhuoqinyue
Copy link
Contributor Author

zhuoqinyue commented Feb 1, 2023

Fine. I've enjoyed my Spring Festival vacation recently. I just returned to the city where I live today.
And I would implement Deque using DequeNode as follow:

class DequeNode {
    prev = null; 
    next = null;
    val: number = 0;
}

If I have no idea to implement Deque, I will refer to linkedlist_deque.java .

@zhuoqinyue
Copy link
Contributor Author

Wait, It means i can use the Array to implement the deque and comment the time complexity? @krahets

@zhuoqinyue
Copy link
Contributor Author

@krahets hey, I've commented the time complexity.
And I will implement Deque using DequeNode for linkedlist_deque

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Thanks! Please address the comments.

@zhuoqinyue
Copy link
Contributor Author

hey, I've fixed all. @krahets

@zhuoqinyue
Copy link
Contributor Author

please check again @krahets

Copy link
Owner

@krahets krahets left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Now merge it.

I recommended turning on the option "Allow edit by the ..." so I can fine-tune this PR.

@krahets krahets merged commit 1d1d13e into krahets:master Feb 4, 2023
@krahets
Copy link
Owner

krahets commented Feb 4, 2023

Moreover, could you help implement linkedlist_deque.js / ts as well?

@krahets krahets added the code Code-related label Feb 4, 2023
@krahets
Copy link
Owner

krahets commented Feb 4, 2023

Please found the finetuned code at 7d0d3df

@zhuoqinyue
Copy link
Contributor Author

zhuoqinyue commented Feb 4, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Code-related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants