8.21
#include <stdio.h> void bubbleSort(int **p, int n); int main(void){ int a[100];
int *b[100];
int n, i, **p; printf("Input your n(n < 100)\n");
scanf("%d", &n);
printf("Input your a[n]\n");
for(i = 0; i < n; i++)
scanf("%d", a + i);
for(i = 0; i < n; i++)
b[i] = a + i;
p = b;
bubbleSort(p, n);
for(i = 0; i < n; i++)
printf("%d ", *b[i]);
printf("\n");
return 0;
} void bubbleSort(int **p, int n){
int i, j, flag = 1;
int *temp;
for(i = 0; flag; i++){
flag = 0;
for(j = n - 1; j > i; j--){
flag = 1;
if(**(p + i) > **(p + j)){
temp = *(p + i);
*(p + i) = *(p + j);
*(p + j) = temp;
}
} }
}
8.20
#include <stdio.h>
#include <string.h> void selectionSort(char **p); int main(void)
{
char a[5][30], *b[5], **p;
int i; for(i = 0; i < 5; i++)
b[i] = a[i];
for(i = 0; i < 5; i++)
scanf("%s", b[i]);
p = b;
selectionSort(p);
printf("\n");
for(i = 0; i < 5; i++)
printf("%s\n", b[i]);
return 0;
} void selectionSort(char **p)
{
int i, j, minj, n = 5;
char *temp; for(i = 0; i < n - 1; i++)
{
minj = i;
for(j = i; j < n; j++)
{
if(strcmp(*(p + j), *(p + minj)) < 0)
minj = j;
}
temp = *(p + i);
*(p + i) = *(p + minj);
*(p + minj) = temp;
} }
8.16
#include <stdio.h> int getnum(char str[], int a[]); int main(void)
{
char str[] = {}, *pstr;
int a[] = {}, total, *p, i;
p = a;
pstr = str;
printf("Input your string\n");
gets(pstr);
total = getnum(str, a);
for(i = ; a[i] != '\0'; i++)
printf("%d ", a[i]);
printf("total = %d\n", total);
return ;
} int getnum(char str[], int a[])
{
int count = , temp = ;
int i = , j = , k = , m = , e10;
char *p;
int *pa;
p = str;
pa = a;
while(*(p + i) != '\0')
{
if((*(p + i) >= '') && (*(p + i) <= ''))
{
j++;
}
else
{
if(j > )
{
temp = *(p + i -) - '';
k = ;
while(k < j)
{
e10 = ;
for(m = ; m <= k; m++)
e10 = e10 * ;
temp = temp + (*(p + i - - k) - '') * e10;
k++;
printf("2th while e10 temp = %d\n", temp);
} //while
*pa = temp;
printf("pa++ = %d\n", *pa);
pa++;
j = ;
count++;
} //if
} //else
i++;
} // while if(j > )
{
temp = *(p + i -) - '';
k = ;
while(k < j)
{
e10 = ;
for(m = ; m <= k; m++)
e10 = e10 * ;
temp = temp + (*(p + i - - k) - '') * e10;
k++;
printf("2th while e10 temp = %d\n", temp);
} //while
*pa = temp;
printf("pa++ = %d\n", *pa);
j = ;
pa++;
count++;
} //if
*pa = '\0';
return count;
}