Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b0c0302

Browse files
refactoring
1 parent 27c0e7d commit b0c0302

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

‎src/main/java/ir/sk/adt/datastructure/array/CircularArray.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ir.sk.adt.datastructure.array;
22

3+
import ir.sk.helper.Point;
34
import ir.sk.helper.Remainder;
45

56
import java.util.Iterator;
@@ -15,6 +16,7 @@ public class CircularArray<T> implements Iterable<T> {
1516

1617
private T[] items;
1718

19+
@Point("Important part of circular Array compare to normal array is head of array is not always 0")
1820
// create a member variable head which points to what should be conceptually viewed
1921
// as the start of the circular array. Rather than shifting around the elements in the array, we just increment
2022
// head by shift Right.
@@ -39,6 +41,9 @@ private int convert(int index) {
3941
return (head + index) % items.length;
4042
}
4143

44+
/**
45+
* one of the best way for rotation
46+
*/
4247
public void rotate(int shiftRight) {
4348
head = convert(shiftRight);
4449
}

‎src/main/java/ir/sk/adt/queue/circularqueue/ArrayCircularQueue.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class ArrayCircularQueue<T> implements Queue<T>, Iterable<T> {
3030
private T[] items;
3131
private int capacity;
3232

33-
// there are another way to calculate front and rear. 1.front = start, rear = start + size
33+
// there are another way to calculate front and rear.
34+
// 1. front = start, rear = start + size
35+
// 2. to how two pointer, front, rear
3436
// front
3537
private int start;
3638
private int size;
@@ -69,7 +71,7 @@ public void enqueue(T item) {
6971
throw new UnsupportedOperationException("Queue is full");
7072
}
7173
// calculate rear
72-
items[(start + size) % capacity] = item;
74+
items[(start + size) % capacity] = item;// or if (start + size == capacity) start = 0
7375
size++;
7476
}
7577

@@ -85,7 +87,7 @@ public T dequeue() {
8587

8688
@Override
8789
public T peek() {
88-
returnnull;
90+
thrownewUnsupportedOperationException("Not implemented");
8991
}
9092

9193
public String toString() {

‎src/main/java/ir/sk/algorithm/basic/RotationShift.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public static void leftShift(int[] array, int startIndex, int endIndex, int unit
5353
array[i] = array[i + unit];
5454
}
5555

56+
// another way of rotation is Circular Array
5657
/**
57-
* shifting - left rotation just one unit
58+
* rotation - left rotation just one unit
5859
*
5960
* @param array the source array.
6061
* @param startIndex starting position
@@ -69,7 +70,7 @@ public static void leftRotate(int[] array, int startIndex, int endIndex) {
6970
}
7071

7172
/**
72-
* shifting - right rotation unit number
73+
* rotation - right rotation unit number
7374
*
7475
* @param array the source array.
7576
* @param startEndex starting position
@@ -98,7 +99,7 @@ public static void rightRotate(int[] array, int startEndex, int endIndex, int un
9899
}
99100

100101
/**
101-
* shifting - left rotation unit number
102+
* rotation - left rotation unit number
102103
*
103104
* @param array the source array.
104105
* @param startIndex starting position

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /