关于快速排序的一些问题
程序代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h> #include <locale.h> #pragma comment(lib,"winmm.lib") int meNu(); int outPut(); int inSert(); int deMand(); int dEl(); int modiFication(); int soRt(); int num=3; struct contacts{ char name[100]; char site[100]; char number[100]; char postcode[100]; char email[100]; }list[3]={{"张三","北京","00000000000","000000","123@"},{"李四","黑龙江","00000000000","000000","456@"},{"张芮嘉","黑龙江","00000000000","000000","789@"}}; int main() { PlaySound(TEXT("1.wav"), NULL, SND_FILENAME | SND_ASYNC|SND_LOOP); system("cls"); system("color 2f"); meNu(); int a; fflush(stdin); scanf("%d",&a); system("cls"); switch(a) { case 1: outPut(); break; case 2: inSert(); break; case 3: deMand(); break; case 4: dEl(); break; case 5: modiFication(); break; case 6: soRt(); break; default: printf("cw"); } return 0; } int meNu()//菜单函数 { printf("\t* 通讯录管理系统 *\n"); printf("\t********************************************************\n"); printf("\t* ①输出全部信息 *\n"); printf("\t* ②添加个人信息 *\n"); printf("\t* ③查询个人信息 *\n"); printf("\t* ④删除个人信息 *\n"); printf("\t* ⑤修改个人信息 *\n"); printf("\t* ⑥信息排序 *\n"); printf("\t 请选择:"); return 0; } int outPut() { int i,box; printf("-----------------------------------------------------------------\n"); printf("|姓名\t|地址\t|电话号码\t|邮编\t|电子邮箱\t\t|\n"); for(i=0;i<num;i++) { printf("-----------------------------------------------------------------\n"); printf("|%s\t|%s\t|%s\t|%s\t|%s\t|\n",list[i].name,list[i].site,list[i].number,list[i].postcode,list[i].email); } printf("-----------------------------------------------------------------\n"); box=MessageBoxA(NULL,"是否返回主页面","系统提示",MB_YESNO); if(box==IDYES) main(); return 0; } int inSert() { int j; do { printf("新建联系人列表:\n\n"); printf("\t姓名:"); fflush(stdin); scanf("%s",&list[num].name); printf("\t地址:"); fflush(stdin); scanf("%s",&list[num].site); printf("\t电话号码:"); fflush(stdin); scanf("%s",&list[num].number); if(strlen(list[num].number)!=11) { MessageBoxA(NULL,"电话号码格式错误","系统提示",MB_OK); main(); break; } printf("\t邮编:"); fflush(stdin); scanf("%s",&list[num].postcode); if(strlen(list[num].postcode)!=6) { MessageBoxA(NULL,"邮编格式错误","系统提示",MB_OK); main(); break; } printf("\t电子邮箱:"); fflush(stdin); scanf("%s",list[num].email); char *p=list[num].email; while(*p) { if(*p=='@') { break; } p++; } if(*p=='\0') { MessageBoxA(NULL,"电子邮箱格式错误","系统提示",MB_OK); main(); break; } num++; printf("是否继续添加:"); fflush(stdin); scanf("%d",&j); }while(j==1); outPut(); return 0; } int deMand() { printf("查询方式(1:姓名;2:手机号码)\n"); printf("请选择:"); int a; int box; int i; char j[100]; char k[100]; fflush(stdin); scanf("%d",&a); switch(a) { case 1: printf("请输入姓名:"); fflush(stdin); scanf("%s",j); system("cls"); printf("|姓名\t|地址\t|电话号码\t|邮编\t|电子邮箱\t\t|\n"); printf("-----------------------------------------------------------------\n"); for(i=0;i<num;i++) { if(strcmp(j,list[i].name)==0) { printf("|%s\t|%s\t|%s\t|%s\t|%s\t|\n",list[i].name,list[i].site,list[i].number,list[i].postcode,list[i].email); break; } } if(i==num) { printf("没有找到!\n"); } printf("-----------------------------------------------------------------\n"); box=MessageBoxA(NULL,"是否返回主页面","系统提示",MB_YESNO); if(box==IDYES) main(); break; case 2: printf("请输入手机号码:"); fflush(stdin); scanf("%s",k); system("cls"); printf("|姓名\t|地址\t|电话号码\t|邮编\t|电子邮箱\t\t|\n"); printf("-----------------------------------------------------------------\n"); for(i=0;i<num;i++) { if(strcmp(k,list[i].number)==0) { printf("|%s\t|%s\t|%s\t|%s\t|%s\t|\n",list[i].name,list[i].site,list[i].number,list[i].postcode,list[i].email); break; } } if(i==num) { printf("没有找到!\n"); } printf("-----------------------------------------------------------------\n"); box=MessageBoxA(NULL,"是否返回主页面","系统提示",MB_YESNO); if(box==IDYES) main(); break; default: box=MessageBoxA(0,"无效选择,选择“是”返回上一级,“否”退回主菜单","系统提示",MB_YESNO|MB_ICONQUESTION); if(box==IDYES) deMand(); else main(); } return 0; } int dEl() { int a,b,i,y; char x[100]; char z[100]; printf("删除方式(1:姓名;2:手机号码)\n"); printf("请选择:"); fflush(stdin); scanf("%d",&a); switch(a) { case 1: printf("请输入姓名:"); fflush(stdin); scanf("%s",&x); for(i=0;i<num;i++) { if(strcmp(x,list[i].name)==0) { y=i; } } for(i=y;i<num;i++) { list[i]=list[i+1]; } num--; if(i==num) { printf("没有找到!\n"); MessageBoxA(NULL,"是否返回主页面","系统提示",MB_YESNO); } main(); break; case 2: printf("请输入手机号码:"); fflush(stdin); scanf("%s",&z); for(i=0;i<num;i++) { if(strcmp(z,list[i].number)==0) { y=i; } } for(i=y;i<num;i++) { list[i]=list[i+1]; } num--; main(); } return 0; } int modiFication() { int i,box; char a[100]; printf("请输入修改人的姓名或手机号码:"); fflush(stdin); scanf("%s",a); for(i=0;i<num;i++) { if((strcmp(a,list[i].name)==0)||(strcmp(a,list[i].number)==0)) { printf("|%s\t|%s\t|%s\t|%s\t|%s\t|\n",list[i].name,list[i].site,list[i].number,list[i].postcode,list[i].email); break; } if((strcmp(a,list[i].name)!=0)||(strcmp(a,list[i].number)!=0)) { printf("没有找到"); box=MessageBoxA(NULL,"是否返回主页面","系统提示",MB_YESNO); if(box==IDYES) main(); } break; } if((strcmp(a,list[i].name)==0)||(strcmp(a,list[i].number)==0)){ printf("修改联系人:\n\n"); printf("\t姓名:"); fflush(stdin); scanf("%s",&list[i].name); printf("\t地址:"); fflush(stdin); scanf("%s",&list[i].site); printf("\t电话号码:"); fflush(stdin); scanf("%s",&list[i].number); if(strlen(list[i].number)!=11) { MessageBoxA(NULL,"电话号码格式错误","系统提示",MB_OK); main(); } printf("\t邮编:"); fflush(stdin); scanf("%s",&list[i].postcode); if(strlen(list[i].postcode)!=6) { MessageBoxA(NULL,"邮编格式错误","系统提示",MB_OK); main(); } printf("\t电子邮箱:"); fflush(stdin); scanf("%s",list[i].email); char *p=list[i].email; while(*p) { if(*p=='@') { break; } p++; } if(*p=='\0') { MessageBoxA(NULL,"电子邮箱格式错误","系统提示",MB_OK); main(); } main();} return 0; } int soRt() { int i; printf("\n当前通讯录目录:\n"); meNu(); printf("\n按姓氏排序:\n"); char p=list[i].name; setlocale (LC_ALL, ""); qsort (p,3,100,strcoll); printf("-----------------------------------------------------------------\n"); printf("|姓名\t|地址\t|电话号码\t|邮编\t|电子邮箱\t\t|\n"); for(i=0;i<num;i++) { printf("-----------------------------------------------------------------\n"); printf("|%s\t|%s\t|%s\t|%s\t|%s\t|\n",list[i].name,list[i].site,list[i].number,list[i].postcode,list[i].email); } printf("-----------------------------------------------------------------\n"); return 0; }