# (DD05) quiks — Class Detailed Design [210 LOC]

| Field | Value |
|-------|-------|
| Fully Qualified Name | `algo_Calc.quiks` |
| Layer | Utility |
| Module | `algo_Calc` |

## Class Overview

`quiks` is a utility class that implements in-place quick sort for integer arrays. It provides the recursive sorting entry point and the partition routine that reorders elements around a pivot. The class is used by the GUI wrapper in `Sortingss` when the user selects Quick Sort.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: partition(int[] num, int start, int end)

### 1. Role
Partitions the active subarray around the last element as pivot. It moves all values smaller than the pivot to the left side and places the pivot into its final sorted position.

### 2. Processing Pattern
```mermaid
flowchart TD
A["partition entry"] --> B["Set pivot to num[end]"]
B --> C["Scan from start to end - 1"]
C --> D["If current value is smaller than pivot, swap with start"]
D --> E["Advance start index"]
C --> F["After scan, swap pivot into start"]
F --> G["Return final pivot index"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array segment being partitioned | Must not be null |
| `start` | `int` | Lower boundary and moving left-partition cursor | Must be within array bounds |
| `end` | `int` | Upper boundary and pivot position | Must be within array bounds and `>= start` |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Read | `num[end]` | Uses the last element as pivot |
| Read/Write | `num[start]`, `num[i]` | Swaps smaller values into the left partition |
| Write | `num[start]`, `num[end]` | Places the pivot in its final position |
| Return | caller | Returns the final pivot index |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `quickSort(int[] num, int start, int end)` | Always called before recursive partitioning |
| Incoming | Caller | Recursive quick sort | Used to split ranges repeatedly |
| Outgoing | None | - | This method is self-contained |

### 6. Per-Branch Detail Blocks
- **Pivot selection block**: Chooses the element at `end` as the pivot, which simplifies boundary handling because the pivot is already inside the active range.
- **Traversal block**: Iterates `i` from `start` to `end - 1`, examining each candidate once.
- **Swap branch**: When `num[i] < pivot`, the current element is swapped with the element at `start`, moving a smaller value into the left partition.
- **Cursor advance branch**: After a successful swap, `start` is incremented so the left partition grows by one slot.
- **Final placement block**: After the scan completes, the pivot is swapped into the current `start` position, which is the first slot after all smaller values.
- **Return block**: Returns the final pivot index so the caller can sort the two remaining subranges independently.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.

---

## Method: quickSort(int[] num, int start, int end)

### 1. Role
Performs recursive quick sort over the subarray bounded by `start` and `end`. It delegates the pivot placement to `partition()` and then sorts the left and right partitions independently.

### 2. Processing Pattern
```mermaid
flowchart TD
A["quickSort entry"] --> B["Call partition with start and end"]
B --> C["If left partition exists, recurse left"]
B --> D["If right partition exists, recurse right"]
C --> E["Return to caller"]
D --> E["Return to caller"]
```

### 3. Parameter Analysis
| Parameter | Type | Meaning | Constraints |
|-----------|------|---------|-------------|
| `num` | `int[]` | Array to be sorted in place | Must not be null |
| `start` | `int` | Lower bound of the active range | Usually `0` or a valid subrange start |
| `end` | `int` | Upper bound of the active range | Usually `num.length - 1` or a valid subrange end |

### 4. CRUD Operations / Called Services
| Operation Type | Target | Description |
|----------------|--------|-------------|
| Call | `partition()` | Places the pivot in its final index and returns that index |
| Call | Recursive `quickSort()` | Sorts the left side if elements remain |
| Call | Recursive `quickSort()` | Sorts the right side if elements remain |

### 5. Dependency Trace
| Direction | Type | Element | Notes |
|-----------|------|---------|-------|
| Incoming | Caller | `Sortingss` button action | Invoked when `key == 3` |
| Outgoing | Callee | `partition(int[] num, int start, int end)` | Core pivot split routine |
| Outgoing | Callee | `quickSort(int[] num, int start, int end)` | Recursive self-call for both halves |

### 6. Per-Branch Detail Blocks
- **Entry branch**: Receives the current array segment and immediately computes the partition index.
- **Left recursion branch**: Runs only when `partition - 1 > start`, which means at least two elements exist on the left side of the pivot boundary.
- **Right recursion branch**: Runs only when `partition + 1 < end`, which means at least two elements exist on the right side of the pivot boundary.
- **Termination behavior**: If neither side satisfies its boundary test, the call returns without further recursion, leaving one-element or empty ranges unchanged.
