Skip to content

feat: add Linked Queue #88

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

Merged
merged 24 commits into from
Jan 8, 2023
Merged

feat: add Linked Queue #88

merged 24 commits into from
Jan 8, 2023

Conversation

co-bby
Copy link
Contributor

@co-bby co-bby commented Jan 5, 2023

*added linkedlist Queue implementation

*added a test to the implementation( I used the tests from array queue implementation but tweak to make the tests uniform on the site)

*updated the Directory.md

@co-bby co-bby changed the title added linkedlist Queue feat: add linkedlist Queue Jan 5, 2023
@Panquesito7 Panquesito7 added the enhancement New feature or request label Jan 5, 2023
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

The implementation looks good! A couple things:

  • The tests are practically identical (if not, they should be, since both queues should implement the same implicit "interface"). Please avoid duplicating them. Can you try:
    1. Adding a Queue Interface
    2. Parameterizing the tests for this interface in terms of the Queue implementation
    3. De-duplicating the Queue tests using this parameterized version
  • Terminology-wise nitpick: I'd just call this a LinkedQueue. LinkedlistQueue violates CamelCase, and LinkedListQueue seems odd (is it a linked list, a queue, or both?).
  • Formatting-wise, please check your comments for typos and grammar mistakes. Many are also missing a space after the //; the comments at the start are pretty oddly formatted, please clean them up using JSDoc.

@co-bby
Copy link
Contributor Author

co-bby commented Jan 5, 2023

The implementation looks good! A couple things:

* The tests are practically identical (if not, they should be, since both queues should implement the same implicit "interface"). Please avoid duplicating them. Can you try:
  
  1. Adding a `Queue` Interface
  2. Parameterizing the tests for this interface in terms of the Queue implementation
  3. De-duplicating the `Queue` tests using this parameterized version

* Terminology-wise nitpick: I'd just call this a `LinkedQueue`. `LinkedlistQueue` violates CamelCase, and `LinkedListQueue` seems odd (is it a linked list, a queue, or both?).

* Formatting-wise, please check your comments for typos and grammar mistakes. Many are also missing a space after the `//`; the comments at the start are pretty oddly formatted, please clean them up using JSDoc.

thanks for the feedback. Working on that!

@co-bby
Copy link
Contributor Author

co-bby commented Jan 5, 2023

The implementation looks good! A couple things:

* The tests are practically identical (if not, they should be, since both queues should implement the same implicit "interface"). Please avoid duplicating them. Can you try:
  
  1. Adding a `Queue` Interface
  2. Parameterizing the tests for this interface in terms of the Queue implementation
  3. De-duplicating the `Queue` tests using this parameterized version

* Terminology-wise nitpick: I'd just call this a `LinkedQueue`. `LinkedlistQueue` violates CamelCase, and `LinkedListQueue` seems odd (is it a linked list, a queue, or both?).

* Formatting-wise, please check your comments for typos and grammar mistakes. Many are also missing a space after the `//`; the comments at the start are pretty oddly formatted, please clean them up using JSDoc.

did you mean I should not duplicate the Queue test? if yes I don't think it will be possible since they have different names.

@appgurueu
Copy link
Contributor

appgurueu commented Jan 6, 2023

did you mean I should not duplicate the Queue test? if yes I don't think it will be possible since they have different names.

It is tricky but definitely possible. Here's a simple example for a fictive generic "Box" container type:

interface Box<T> {
	peek(): T
}

// These two classes are deliberately identical.

class BoxA<T> implements Box<T> {
	content: T
	constructor(content: T) {
		this.content = content
	}
	peek(): T {
		return this.content
	}
}

class BoxB<T> implements Box<T> {
	content: T
	constructor(content: T) {
		this.content = content
	}
	peek(): T {
		return this.content
	}
}

// Test function parameterized in terms of the class

type BoxConstructor = new<T>(content: T) => Box<T>

function test(Box: BoxConstructor) {
	const content = 42
	const c = new Box<number>(content)
	// This is just for a simple example that works in `ts-node`;
        // you'd instead use Jest's `expect(...).toBe(...)` here.
	if (c.peek() != content)
		throw new Error("test failed")
}

test(BoxA)
test(BoxB)

In terms of files, I'd like it split up as follows:

  • queue.ts for the interface;
  • array_queue.ts for the array implementation;
  • linked_queue.ts for the linked implementation;

Ideally, the tests would have the same structure:

  • test/queue.ts for the parameterized test (test function in the above example), which is exported;
  • test/array_queue.ts as a simple one-liner calling the parameterized test for the imported array queue;
  • test/linked_queue.ts analogeously as a one-liner calling the test for the imported linked queue

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

This seems to be going in the right direction. Please don't duplicate the Queue interface, but rather export it from a queue.ts file which both implementations import.

@co-bby
Copy link
Contributor Author

co-bby commented Jan 6, 2023

This seems to be going in the right direction. Please don't duplicate the Queue interface, but rather export it from a queue.ts file which both implementations import.

is everything ok now?

@appgurueu
Copy link
Contributor

This seems to be going in the right direction. Please don't duplicate the Queue interface, but rather export it from a queue.ts file which both implementations import.

is everything ok now?

Not quite: The tests still need to be deduplicated as I have described.

@co-bby
Copy link
Contributor Author

co-bby commented Jan 6, 2023

This seems to be going in the right direction. Please don't duplicate the Queue interface, but rather export it from a queue.ts file which both implementations import.

is everything ok now?

Not quite: The tests still need to be deduplicated as I have described.

can you please check this out

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

Looking good! Only minor things left:

  • Please lowercase Queue.test.ts to queue.test.ts to follow our naming conventions;
  • Please remove leaading and trailing newlines

@co-bby
Copy link
Contributor Author

co-bby commented Jan 7, 2023

* Please remove leaading and trailing newlines

Looking good! Only minor things left:

* Please lowercase `Queue.test.ts` to `queue.test.ts` to follow our naming conventions;

* Please remove leaading and trailing newlines

I'm confused with the leading and trailing newlines can you please show me an example?

@co-bby co-bby requested review from appgurueu and removed request for Panquesito7 and raklaptudirm January 8, 2023 03:26
appgurueu
appgurueu previously approved these changes Jan 8, 2023
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@appgurueu appgurueu changed the title feat: add linkedlist Queue feat: add Linked Queue Jan 8, 2023
raklaptudirm
raklaptudirm previously approved these changes Jan 8, 2023
@co-bby
Copy link
Contributor Author

co-bby commented Jan 8, 2023

Thank you for your contribution!

You are welcome! I have learnt a lot from you

@raklaptudirm raklaptudirm merged commit 124890c into TheAlgorithms:master Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants