Skip to content

Commit 4a60b9a

Browse files
authored
refactor: groups all data structures (#113)
* refactor: groups all data structures * refactor: groups hashing files in set/map folder
1 parent 63cbf8f commit 4a60b9a

27 files changed

+41
-41
lines changed
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { DoublyLinkedList } from "../doubly_linked_list";
2+
import { testLinkedList } from "./linked_list";
3+
4+
describe("DoublyLinkedList", () => {
5+
testLinkedList(DoublyLinkedList);
6+
7+
it("should reverse the list", () => {
8+
const list: DoublyLinkedList<number> = new DoublyLinkedList<number>();
9+
10+
list.append(1);
11+
list.append(2);
12+
list.append(3);
13+
list.reverse();
14+
15+
expect(list.get(0)).toBe(3);
16+
expect(list.get(1)).toBe(2);
17+
});
18+
19+
it("should return null for reverse when list is empty", () => {
20+
const list: DoublyLinkedList<number> = new DoublyLinkedList<number>();
21+
22+
expect(list.reverse()).toBeNull();
23+
});
24+
});

data_structures/hashing/hash_map.ts renamed to data_structures/map/hash_map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Map } from "../map";
1+
import { Map } from "./map";
22

33
/**
44
* Represents a hash map.

data_structures/map.ts renamed to data_structures/map/map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HashMapEntry } from "./hashing/hash_map";
1+
import { HashMapEntry } from "./hash_map";
22

33
/**
44
* This interface is a representation of the Map data structure.

data_structures/hashing/test/hash_map.test.ts renamed to data_structures/map/test/hash_map.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HashMap } from "../hash_map";
1+
import { HashMap } from "../../map/hash_map";
22

33
describe("Hash Map", () => {
44
let hashMap: HashMap<string, number>;
File renamed without changes.
File renamed without changes.

data_structures/stack_queue.ts renamed to data_structures/queue/stack_queue.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/**
2-
* A Stack Based Queue Implementation.
3-
* The Queue data structure which follows the FIFO (First in First Out) rule.
4-
* The dequeue operation in a normal stack based queue would be o(n), as the entire has to be shifted
5-
* With the help of two stacks, the time complexity of this can be brought down to amortized-O(1).
6-
* Here, one stack acts as an Enqueue stack where elements are added.
2+
* A Stack Based Queue Implementation.
3+
* The Queue data structure which follows the FIFO (First in First Out) rule.
4+
* The dequeue operation in a normal stack based queue would be o(n), as the entire has to be shifted
5+
* With the help of two stacks, the time complexity of this can be brought down to amortized-O(1).
6+
* Here, one stack acts as an Enqueue stack where elements are added.
77
* The other stack acts as a dequeue stack which helps in dequeuing the elements
88
*/
99

10-
import { Queue } from './queue';
11-
import { Stack } from './stack';
12-
13-
export class StackQueue<T> implements Queue<T>{
10+
import { Stack } from "../stack/stack";
11+
import { Queue } from "./queue";
1412

13+
export class StackQueue<T> implements Queue<T> {
1514
private enqueueStack: Stack<T> = new Stack<T>();
1615
private dequeueStack: Stack<T> = new Stack<T>();
1716

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

4544
/**
4645
* Shifts the elements from the enqueueStack to the dequeueStack
47-
* In the worst case, all the elements from the enqueue stack needs to shifted, which needs O(n) time.
46+
* In the worst case, all the elements from the enqueue stack needs to shifted, which needs O(n) time.
4847
* However, after the shift, elements can de dequeued at O(1).
4948
* This helps in dequeuing the elements in amortized O(1) time.
5049
*/

data_structures/test/queue.ts renamed to data_structures/queue/test/queue.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Queue } from '../queue';
2+
23
type QueueConstructor = new <T>() => Queue<T>
34
export function testQueue(Queue: QueueConstructor) {
45
it("enqueue should add a new element to the queue", () => {

data_structures/hashing/hash_map_set.ts renamed to data_structures/set/hash_map_set.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Map } from "../map";
2-
import { MapSet } from "../map_set";
3-
import { HashMap } from "./hash_map";
1+
import { Map } from "../map/map";
2+
import { HashMap } from "../map/hash_map";
3+
import { MapSet } from "./map_set";
44

55
/**
66
* This class is a representation of the Set data structure based on a hash map.
File renamed without changes.
File renamed without changes.

data_structures/linked_list_stack.ts renamed to data_structures/stack/linked_list_stack.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SinglyLinkedList } from "./singly_linked_list";
1+
import { SinglyLinkedList } from "../list/singly_linked_list";
22

33
/**
44
* This is an implementation of a stack, based on a linked list.
File renamed without changes.

data_structures/test/doubly_linked_list.test.ts

-24
This file was deleted.

0 commit comments

Comments
 (0)