Skip to content

Commit 5e3f865

Browse files
committed
⚡ array queque
1 parent c23545f commit 5e3f865

37 files changed

+278
-66
lines changed

Data_Structures/Arrays/Array.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package data_structures.arrays;
2+
13
import java.util.Arrays;
24

35
public class Array {

Data_Structures/Arrays/ArrayTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package data_structures.arrays;
2+
13
public class ArrayTest {
24

35

Data_Structures/Arrays/DynamicArray.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import java.io.*;
1+
package data_structures.arrays;
2+
23
import java.util.*;
34

45
public class DynamicArray {

Data_Structures/Arrays/MergeSortedArrays.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//merge sorted Array
1+
package data_structures.arrays;//merge sorted Array
22

33
class MergeSortedArrays {
44

Data_Structures/Arrays/ReverseLinkedList.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import java.util.LinkedList;
1+
package data_structures.arrays;
2+
23
public class ReverseLinkedList{
34
static Node head;
45

Data_Structures/Arrays/StringPermutation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package data_structures.arrays;
2+
13
/**
24
* Time Complexity: O(2n) Linear time
35
* Space Complexity: O(1) constant time

Data_Structures/Arrays/TwoSum.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package data_structures.arrays;
2+
13
import java.util.HashMap;
24
import java.util.Map;
35

Data_Structures/hashtables/UniqueCharacter.java

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package data_structures.queues.array_queue;
2+
3+
import java.util.NoSuchElementException;
4+
5+
public class ArrayQueue {
6+
7+
private Employee[] queue;
8+
private int front;
9+
private int back;
10+
11+
public ArrayQueue(int capacity) {
12+
queue = new Employee[capacity];
13+
}
14+
15+
public void add(Employee employee) {
16+
if (back == queue.length) {
17+
Employee[] newArray = new Employee[2 * queue.length];
18+
System.arraycopy(queue, 0, newArray, 0, queue.length);
19+
queue = newArray;
20+
}
21+
22+
queue[back] = employee;
23+
back++;
24+
}
25+
26+
public Employee remove() {
27+
if (size() == 0) {
28+
throw new NoSuchElementException();
29+
}
30+
31+
Employee employee = queue[front];
32+
queue[front] = null;
33+
front++;
34+
if (size() == 0) {
35+
front = 0;
36+
back = 0;
37+
}
38+
39+
return employee;
40+
}
41+
42+
public Employee peek() {
43+
if (size() == 0) {
44+
throw new NoSuchElementException();
45+
}
46+
47+
return queue[front];
48+
}
49+
50+
public int size() {
51+
return back - front;
52+
}
53+
54+
public void printQueue() {
55+
for (int i = front; i < back; i++) {
56+
System.out.println(queue[i]);
57+
}
58+
}
59+
}

Data_Structures/linked_lists/jdk_linked_list/Employee.java renamed to Data_Structures/queues/array_queue/Employee.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
package data_structures.queues.array_queue;
2+
13
public class Employee {
24

35
private String firstName;
@@ -62,5 +64,4 @@ public String toString() {
6264
", id=" + id +
6365
'}';
6466
}
65-
66-
}
67+
}

0 commit comments

Comments
 (0)