Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitto committed Apr 12, 2020
1 parent 0e9f0ef commit d4c5a0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
34 changes: 17 additions & 17 deletions src/array/DynamicArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public String toString() {
}

/**
* 动态扩缩容
* Expand or shrinkage capacity dynamically
*/
private void resize(int newCapacity) {
if(newCapacity <= size) {
Expand All @@ -69,7 +69,7 @@ private void resize(int newCapacity) {
}

/**
* O(n)
* Time complexity: O(n)
*/
public void add(int index, E e) {
if(index < 0 || index > size) {
Expand All @@ -89,22 +89,22 @@ public void add(int index, E e) {
}

/**
* O(n)
* Time complexity: O(n)
*/
public void addFirst(E e) {
add(0, e);
}

/**
* amortized time complexity: O(1)
* Amortized time complexity: O(1)
*/
public void addLast(E e) {
add(size, e);
}

/**
* @author: Kitto
* O(n)
* Time complexity: O(n)
*/
public void add(E[] arr) {
if(arr == null) {
Expand All @@ -123,7 +123,7 @@ public void add(E[] arr) {
}

/**
* O(1)
* Time complexity: O(1)
*/
public void set(int index, E e) {
if(index < 0 || index >= size) {
Expand All @@ -133,7 +133,7 @@ public void set(int index, E e) {
}

/**
* O(1)
* Time complexity: O(1)
*/
public E get(int index) {
if(index < 0 || index >= size) {
Expand All @@ -143,21 +143,21 @@ public E get(int index) {
}

/**
* O(1)
* Time complexity: O(1)
*/
public E getFirst() {
return get(0);
}

/**
* O(1)
* Time complexity: O(1)
*/
public E getLast() {
return get(size - 1);
}

/**
* O(n)
* Time complexity: O(n)
*/
public int find(E e) {
for(int i = 0; i < size; i++) {
Expand All @@ -170,7 +170,7 @@ public int find(E e) {

/**
* @author: Kitto
* O(n)
* Time complexity: O(n)
*/
public int[] findAll(E e) {
ArrayList<Integer> list = new ArrayList<>();
Expand All @@ -188,14 +188,14 @@ public int[] findAll(E e) {
}

/**
* O(n)
* Time complexity: O(n)
*/
public boolean contains(E e) {
return find(e) != -1;
}

/**
* O(n)
* Time complexity: O(n)
*/
public E remove(int index) {
if(index < 0 || index >= size) {
Expand All @@ -219,21 +219,21 @@ public E remove(int index) {
}

/**
* O(n)
* Time complexity: O(n)
*/
public E removeFirst() {
return remove(0);
}

/**
* amortized time complexity: O(1)
* Amortized time complexity: O(1)
*/
public E removeLast() {
return remove(size - 1);
}

/**
* O(n)
* Time complexity: O(n)
*/
public int removeElement(E e) {
int index = find(e);
Expand All @@ -245,7 +245,7 @@ public int removeElement(E e) {

/**
* @author: Kitto
* O(n²) FIXME The indexes have changed after remove the first matched element.
* Time complexity: O(n²) FIXME The indexes have changed after remove the first matched element.
*/
public int[] removeAllElements(E e) {
int[] indexes = findAll(e);
Expand Down
6 changes: 3 additions & 3 deletions src/stack/ArrayStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public boolean isEmpty() {
}

/**
* amortized time complexity: O(1)
* Amortized time complexity: O(1)
*/
@Override
public void push(E e) {
arr.addLast(e);
}

/**
* amortized time complexity: O(1)
* Amortized time complexity: O(1)
*/
@Override
public E pop() {
Expand All @@ -50,7 +50,7 @@ public E pop() {
}

/**
* O(1)
* Time complexity: O(1)
*/
@Override
public E peek() {
Expand Down

0 comments on commit d4c5a0c

Please sign in to comment.