Need me to do the address book contacts and telephone number bubble sort;
/* address book management table */
Typedef struct _cmn_adr_mng_t {
Char name [CMN_ADR_NAME_STRMAX]; Former *//*
Char number [CMN_ADR_TELNUM_STRMAX];/* * phone our/
} cmn_adr_mng_t;
/* address book management table */
Extern cmn_adr_mng_t cmn_adr_mng_tbl [CMN_ADR_SAVE_MAX];
/* the total number of contacts saved table */
Typedef unsigned short cmn_adr_num_mng_t;
/* the total number of contacts saved table */
Extern cmn_adr_num_mng_t cmn_adr_num_mng_tbl;
Here is my reference other people's code, and try to write, but this place appeared bug;
TMP and cmn_adr_mng_tbl [I] number at the beginning of place appear red tilde;
Thought for more than two hours is really can't think of a solution;
For help, give advice or comments please,
TMP - & gt; Number=cmn_adr_mng_tbl [I] number;
Cmn_adr_mng_tbl [I] number=cmn_adr_mng_tbl [j]. Journal of number;
Cmn_adr_mng_tbl [j] number=TMP - & gt; number;
Int adr_sort (int mode)
{
Int n=cmn_adr_num_mng_tbl;
TMP cmn_adr_mng_t *=(cmn_adr_mng_t *) malloc (sizeof (cmn_adr_mng_t));
The switch (mode)
{
Case 0:
for (int i=0; i
For (int j=I + 1; J & lt; n; J++)
{
If (STRCMP (cmn_adr_mng_tbl [I]. Name, cmn_adr_mng_tbl [j]. Name)) {
Strcpy (TMP - & gt; Name, cmn_adr_mng_tbl [I] name);
Strcpy (cmn_adr_mng_tbl [I]. Name, cmn_adr_mng_tbl [j]. Name);
Strcpy (cmn_adr_mng_tbl [j]. Name, TMP - & gt; Name);
TMP - & gt; Number=cmn_adr_mng_tbl [I] number;
Cmn_adr_mng_tbl [I] number=cmn_adr_mng_tbl [j]. Journal of number;
Cmn_adr_mng_tbl [j] number=TMP - & gt; number;
}
}
}
Case 1:
for (int i=0; i
For (int j=I + 1; J & lt; n; J++)
{
If (cmn_adr_mng_tbl [I] number & gt; Cmn_adr_mng_tbl [j] number)
{
Strcpy (TMP - & gt; Name, cmn_adr_mng_tbl [I] name);
Strcpy (cmn_adr_mng_tbl [I]. Name, cmn_adr_mng_tbl [j]. Name);
Strcpy (cmn_adr_mng_tbl [j]. Name, TMP - & gt; Name);
TMP - & gt; Number=cmn_adr_mng_tbl [I] number;
Cmn_adr_mng_tbl [I] number=cmn_adr_mng_tbl [j]. Journal of number;
Cmn_adr_mng_tbl [j] number=TMP - & gt; number;
}
}
}
Default:
Cmn_err_log (FUNC_NUM_ADR_SORT __LINE__, OPTION_ERROR);
Return A_ADR_OPTION_ERROR;
}
CodePudding user response:
Just like ordinary bubble sort, is also a comparison, exchangeCodePudding user response:
Declare a temporary structure variables, and then traverse structure arrays, qualified with the temporary structure variables