Skip to content

refactor: groups all data structures #113

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data_structures/hashing/hash_map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Map } from "../map";
import { Map } from "../map/map";

/**
* Represents a hash map.
Expand Down
2 changes: 1 addition & 1 deletion data_structures/hashing/hash_map_set.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Map } from "../map";
import { Map } from "../map/map";
import { MapSet } from "../map_set";
import { HashMap } from "./hash_map";

Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions data_structures/list/test/doubly_linked_list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DoublyLinkedList } from "../doubly_linked_list";
import { testLinkedList } from "./linked_list";

describe("DoublyLinkedList", () => {
testLinkedList(DoublyLinkedList);

it("should reverse the list", () => {
const list: DoublyLinkedList<number> = new DoublyLinkedList<number>();

list.append(1);
list.append(2);
list.append(3);
list.reverse();

expect(list.get(0)).toBe(3);
expect(list.get(1)).toBe(2);
});

it("should return null for reverse when list is empty", () => {
const list: DoublyLinkedList<number> = new DoublyLinkedList<number>();

expect(list.reverse()).toBeNull();
});
});
2 changes: 1 addition & 1 deletion data_structures/map.ts → data_structures/map/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HashMapEntry } from "./hashing/hash_map";
import { HashMapEntry } from "../hashing/hash_map";

/**
* This interface is a representation of the Map data structure.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* A Stack Based Queue Implementation.
* The Queue data structure which follows the FIFO (First in First Out) rule.
* The dequeue operation in a normal stack based queue would be o(n), as the entire has to be shifted
* With the help of two stacks, the time complexity of this can be brought down to amortized-O(1).
* Here, one stack acts as an Enqueue stack where elements are added.
* A Stack Based Queue Implementation.
* The Queue data structure which follows the FIFO (First in First Out) rule.
* The dequeue operation in a normal stack based queue would be o(n), as the entire has to be shifted
* With the help of two stacks, the time complexity of this can be brought down to amortized-O(1).
* Here, one stack acts as an Enqueue stack where elements are added.
* The other stack acts as a dequeue stack which helps in dequeuing the elements
*/

import { Queue } from './queue';
import { Stack } from './stack';

export class StackQueue<T> implements Queue<T>{
import { Stack } from "../stack/stack";
import { Queue } from "./queue";

export class StackQueue<T> implements Queue<T> {
private enqueueStack: Stack<T> = new Stack<T>();
private dequeueStack: Stack<T> = new Stack<T>();

Expand Down Expand Up @@ -44,7 +43,7 @@ export class StackQueue<T> implements Queue<T>{

/**
* Shifts the elements from the enqueueStack to the dequeueStack
* In the worst case, all the elements from the enqueue stack needs to shifted, which needs O(n) time.
* In the worst case, all the elements from the enqueue stack needs to shifted, which needs O(n) time.
* However, after the shift, elements can de dequeued at O(1).
* This helps in dequeuing the elements in amortized O(1) time.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Queue } from '../queue';

type QueueConstructor = new <T>() => Queue<T>
export function testQueue(Queue: QueueConstructor) {
it("enqueue should add a new element to the queue", () => {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SinglyLinkedList } from "./singly_linked_list";
import { SinglyLinkedList } from "../list/singly_linked_list";

/**
* This is an implementation of a stack, based on a linked list.
Expand Down
File renamed without changes.
24 changes: 0 additions & 24 deletions data_structures/test/doubly_linked_list.test.ts

This file was deleted.