//数组 Swift创建数组一定要制定存放的元素类型
let arr1 = [Int]()var arr2 = [String]()
//添加元素arr2.append("zhangsan")print(arr2)//修改arr2[0] = "lisi"print(arr2)
//字面量创建数组var arr3 = ["zhangsan","lisi","wanger","mz"]
//删除//根据下标表删除arr3.remove(at: 0)print(arr3)
//删除最后一个元素arr3.removeLast()//arr3.remove(at: 2)//删除第一个元素arr3.removeFirst()//删除所有元素arr3.removeAll()//获取数组元素个数print(arr3.count)print(arr3)//数组的遍历var arr4 = ["huqiangu","shaqianmo","dongfangyuqing","tangbao","zunshang"]for item in arr4 { print(item)}for (i,Item) in arr4.enumerated() { print("item:\(Item)index:\(i)")}//数组排序arr4.sort()print(arr4)//冒泡排序var numArr = [8, 4, 3, 7, 1, 5]//冒泡排序,双层for循环,外层控制趟数,内层控制每趟比较次数//外层控制趟数for i in 0..号是升序,<号是降序 if numArr[j] > numArr[j+1]{ let temp = numArr[j] numArr[j] = numArr[j+1] numArr[j+1] = temp} } print(numArr)}// 1/*var numArr = [8, 4, 3, 7, 1, 5]//外层控制趟数for i in 0..numArr[j+1]{ let temp = numArr[j] numArr[j] = numArr[j+1] numArr[j+1] = temp } }}*///2// var numArr = [8, 4, 3, 7, 1, 5]//for i in 0..numArr[j+1]{// let temp = numArr[j]// numArr[j] = numArr[j+1]// numArr[j+1] = temp// }//}//3//var numArr = [8, 4, 3, 7, 1, 5]//for i in 0..numArr[j+1] {// let temp = numArr[j]// numArr[j] = numArr[j+1]// numArr[j+1] = temp// }// }//}//4//var n = [8, 4, 3, 7, 1, 5]//for i in 0..n[j+1]{// let temp = n[j]// n[j] = n[j+1]// n[j+1] = temp}}//}////5//var n1 = [8, 4, 3, 7, 1, 5]//for i in 0..n1[o+1]{// let temp = n1[o]// n1[o] = n1[o+1]// n1[o+1] = temp// }//}//}//6//var numArr = [8, 4, 3, 7, 1, 5]//for i in 0..numArr[j+1] {// let temp = numArr[j]// numArr[j] = numArr[j+1]// numArr[j+1] = temp// }// }//}//7//var numarr = [8, 4, 3, 7, 1, 5]//for i in 0..numarr[j+1]{// let temp = numarr[j]// numarr[j]=numarr[j+1]// numarr[j+1] = temp// }// }//}//8//var num = [8, 4, 3, 7, 1, 5]//for i in 0..num[j+1]{// let temp = num[j]// num[j]=num[j+1]// num[j+1]=temp// }// // }//}//9 //var nu = [8, 4, 3, 7, 1, 5]//for i in 0..nu[t+1]{// let temp = nu[t]// nu[t]=nu[t+1]// nu[t+1] = temp// }// }//}//10//var u = [8, 4, 3, 7, 1, 5]//for i in 0..u[p+1] {
// let temp = u[p]
// u[p] = u[p+1]
// u[p+1] = temps
// }
//
// }
//print(u)
//}
//元素的插入
var arr5 = ["a","b","c","d"]
//下标值要小于等于数组元素个数
arr5.insert("f", at: 4)
print(arr5)
//字典 key值唯一,value可变 创建字典和创建数组是一样的,创建同时要制定key和value的值的类型
let dict = [String:Int]()
let dict2 = ["name":"yasuo", "age":18, "height":1.8 ] as [String : Any]
//访问字典元素
print("国服第一亚索"+(dict2["name"] as! String))
var dic3 = ["name":"manzi","gender":"妖","skill":"蛮三刀"]
//改(找得到key值就是改,找不到就是增加)
dic3["gender"] = "汉子"
//添加
dic3["hpbby"] = "zhaomeizi"
print(dic3)
//字典的删除
//dic3.removeValue(forKey: "gender")
//print(dic3)
//字典的遍历
//遍历的键值对
for value in dic3{
print(value)
}
//遍历字典key值
for key in dic3.keys{
print(key)
}
//遍历字典的value值
for value in dic3.values{
print(value)
}