import org.junit.test;
/** * @author 大跳蚤
* @create 2020-11-29
* @describe 演算法的考查:陣列的複製、反轉、查詢(線性查詢、二分法查詢)
* ** */
public
class
arraytest1
;//陣列的複製
@test
public
void
copyarr()
for(string i : newarr)
}//陣列的反轉
@test
public
void
reverse()
//方法二:
// for(int i = 0,j = arr.length - 1;i < j;i++,j--)
//方法三:
for(int i = arr.length-
1,j =
0; i>=
0; i--
,j++
)for
(string i : newarr)
}//陣列的查詢
//線性查詢
@test
public
void
search()
}if(flag)
}//二分法查詢
//二分法查詢:(熟悉)
//前提:所要查詢的陣列必須有序。
@test
public
void
search1()
; int key1 =
210;
int head =0;
int end = arr1.length-1;
boolean flag =
true
;while
(head <= end)
else
if(key1 > arr1[middle]
)else}if
(flag)
}}
陣列的複製 查詢 刪除
陣列 複製1 陣列的複製 淺複製 源陣列 string names 新陣列 string newnames names names 1 李飛 遍歷新陣列 for string name newnames 缺點 修改原陣列後,新陣列的資料也發生了變換陣列 複製2 陣列的複製 深複製 源陣列 strin...
30 陣列的反轉 排序 查詢
public class arraytest 陣列的複製 string arr2 new string arr1.length for int i 0 i arr2.length i 遍歷arr1 system.out.println 遍歷arr1 for int i 0 i arr1.length...
陣列的反轉
題目 給定乙個 32 位有符號整數,將整數中的數字進行反轉。示例1 輸入 123 輸出 321 示例2 輸入 123 輸出 321 原理 利用棧的先進後出的原理,先將乙個乙個數壓入棧中,出棧同時組合成所需結果。注意 範圍限制以及符號判定等細節 include include include incl...