mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-10-31 02:17:06 +08:00 
			
		
		
		
	Bug fixes and improvements (#1472)
* preorder, inorder, postorder -> pre-order, in-order, post-order * Bug fixes * Bug fixes * Update what_is_dsa.md * Sync zh and zh-hant versions * Sync zh and zh-hant versions. * Update performance_evaluation.md and time_complexity.md * Add @khoaxuantu to the landing page. * Sync zh and zh-hant versions * Add @ khoaxuantu to the landing page of zh-hant and en versions. * Sync zh and zh-hant versions. * Small improvements * @issue : #1450 (#1453) Fix writing "obsecure" to "obscure" Co-authored-by: Gaya <kheliligaya@gmail.com> * Update the definition of "adaptive sorting". * Update n_queens_problem.md * Sync zh, zh-hant, and en versions. --------- Co-authored-by: Gaya-Khelili <50716339+Gaya-Khelili@users.noreply.github.com> Co-authored-by: Gaya <kheliligaya@gmail.com>
This commit is contained in:
		| @ -72,6 +72,9 @@ func (q *arrayDeque) pushLast(num int) { | ||||
| /* 佇列首出列 */ | ||||
| func (q *arrayDeque) popFirst() any { | ||||
| 	num := q.peekFirst() | ||||
| 	if num == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	// 佇列首指標向後移動一位 | ||||
| 	q.front = q.index(q.front + 1) | ||||
| 	q.queSize-- | ||||
| @ -81,6 +84,9 @@ func (q *arrayDeque) popFirst() any { | ||||
| /* 佇列尾出列 */ | ||||
| func (q *arrayDeque) popLast() any { | ||||
| 	num := q.peekLast() | ||||
| 	if num == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 	q.queSize-- | ||||
| 	return num | ||||
| } | ||||
|  | ||||
| @ -49,6 +49,10 @@ func (q *arrayQueue) push(num int) { | ||||
| /* 出列 */ | ||||
| func (q *arrayQueue) pop() any { | ||||
| 	num := q.peek() | ||||
| 	if num == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// 佇列首指標向後移動一位,若越過尾部,則返回到陣列頭部 | ||||
| 	q.front = (q.front + 1) % q.queCapacity | ||||
| 	q.queSize-- | ||||
|  | ||||
| @ -46,9 +46,13 @@ func TestQueue(t *testing.T) { | ||||
| } | ||||
|  | ||||
| func TestArrayQueue(t *testing.T) { | ||||
|  | ||||
| 	// 初始化佇列,使用佇列的通用介面 | ||||
| 	capacity := 10 | ||||
| 	queue := newArrayQueue(capacity) | ||||
| 	if queue.pop() != nil { | ||||
| 		t.Errorf("want:%v,got:%v", nil, queue.pop()) | ||||
| 	} | ||||
|  | ||||
| 	// 元素入列 | ||||
| 	queue.push(1) | ||||
|  | ||||
| @ -23,7 +23,7 @@ fn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: & | ||||
|             backtrack(state.clone(), choices, selected, res); | ||||
|             // 回退:撤銷選擇,恢復到之前的狀態 | ||||
|             selected[i] = false; | ||||
|             state.remove(state.len() - 1); | ||||
|             state.pop(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -27,7 +27,7 @@ fn backtrack(mut state: Vec<i32>, choices: &[i32], selected: &mut [bool], res: & | ||||
|             backtrack(state.clone(), choices, selected, res); | ||||
|             // 回退:撤銷選擇,恢復到之前的狀態 | ||||
|             selected[i] = false; | ||||
|             state.remove(state.len() - 1); | ||||
|             state.pop(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -113,7 +113,7 @@ fn linear_log_recur(n: i32) -> i32 { | ||||
|         return 1; | ||||
|     } | ||||
|     let mut count = linear_log_recur(n / 2) + linear_log_recur(n / 2); | ||||
|     for _ in 0..n as i32 { | ||||
|     for _ in 0..n { | ||||
|         count += 1; | ||||
|     } | ||||
|     return count; | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Yudong Jin
					Yudong Jin