int main(int argc, const char * argv[]) {
@autoreleasepool {
// 作业1
// 定义一个数组 存放分组
// , @"G", @"H", @"I", @"J",@"", @"K", @"L", @"M", @"N", @"O", @"P", @"Q", @"R", @"S", @"T", @"U", @"V", @"W", @"X", @"Y", @"Z"
NSMutableArray *key = [NSMutableArray arrayWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", nil];
// 创建对象
Contact *c1 = [[Contact alloc] initWithName:@"huangrong" phone:@"15419848946" group:@"A"];
Contact *c2 = [[Contact alloc] initWithName:@"guojing" phone:@"15454638946" group:@"C"];
Contact *c3 = [[Contact alloc] initWithName:@"yangguo" phone:@"15417852946" group:@"A"];
Contact *c4 = [[Contact alloc] initWithName:@"xiaolongnv" phone:@"15459848946" group:@"D"];
Contact *c5 = [[Contact alloc] initWithName:@"jinlunfawang" phone:@"15474848946" group:@"A"];
Contact *c6 = [[Contact alloc] initWithName:@"limochou" phone:@"25479848946" group:@"A"];
Contact *c7 = [[Contact alloc] initWithName:@"" phone:@"" group:@"D"];
c1.sex = @"男";
c2.sex = @"女";
c3.sex = @"男";
c4.sex = @"女";
c5.sex = @"男";
c6.sex = @"女";
c1.age = 18;
c2.age = 20;
c3.age = 30;
c4.age = 24;
c5.age = 14;
c6.age = 22;
// 创建空数组 按分组 存放联系人
NSMutableArray *arrA = [NSMutableArray array];
NSMutableArray *arrB = [NSMutableArray array];
NSMutableArray *arrC = [NSMutableArray array];
NSMutableArray *arrD = [NSMutableArray array];
NSMutableArray *arrE = [NSMutableArray array];
NSMutableArray *arrF = [NSMutableArray array];
NSMutableArray *person = [NSMutableArray arrayWithObjects:arrA, arrB, arrC, arrD, arrE, arrF, nil];
// 创建字典
DicBook *dic = [[DicBook alloc] initWithArray:person arr2:key];
// 将联系人对象添加到 字典中(对应分组)
[dic addGroupNum:c1];
[dic addGroupNum:c2];
[dic addGroupNum:c3];
[dic addGroupNum:c4];
[dic addGroupNum:c5];
[dic addGroupNum:c6];
[dic addGroupNum:c7];
// 按照分组取相应的联系人
// NSMutableArray *arr = [dic searchGroupMember:@"A"];
// if (arr.count == 0) {
// NSLog(@"所查询的分组中没有联系人");
// } else {
// // 排序
// for (int i = 0; i < arr.count - 1; i++) {
// for (int j = 0; j < arr.count - 1 - i; j++) {
// Contact *temp1 = arr[j];
// Contact *temp2 = arr[j + 1];
// // 使用compare方法进行比较
// if ([temp1.name compare:temp2.name] > 0) {
// [arr exchangeObjectAtIndex:j withObjectAtIndex:j + 1];
// }
// }
// }
// // 输出
// for (int i = 0; i < arr.count; i++) {
// Contact *temp = arr[i];
// [temp sayHi];
// }
// }
// 根据电话号码查找某人
// [dic searchByPhone:@"15419848946"];
// 获取女性所有联系人
// NSMutableArray *arr = [dic searchWomenMember];
// // 遍历数组
// if (arr.count == 0) {
// NSLog(@"通讯录中没有女性联系人!");
// } else {
// // 排序
// for (int i = 0; i < arr.count - 1; i++) {
// for (int j = 0; j < arr.count - 1 - i; j++) {
// Contact *temp1 = arr[j];
// Contact *temp2 = arr[j + 1];
// // 使用compare方法进行比较
// if (temp1.age < temp2.age) {
// [arr exchangeObjectAtIndex:j withObjectAtIndex:j + 1];
// }
// }
// }
// }
// // 输出
// for (int i = 0; i < arr.count; i++) {
// Contact *temp = arr[i];
// [temp sayHi];
// }
// 根据姓名删除某个联系人
// [dic removeByName:@"guojing"];
// 删除某个分组的全部联系人
[dic removeAllGroup:@"A"];
[dic showAll];
// 把字典中的东西取出来
// [dic showAll];