#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
int *fun(int num)
{
int *ptr = (int *)malloc(sizeof(int)*num);
return ptr;
}
void intput(int *ptr, int n)
{
for(int i = 0; i < n; i++)
{
scanf("%d", ptr+1);
}
}
void sort_(int *p, int n)
{
int k = 0;
int j = 0;
int temp = 0;
for(k = 1; k < n; k++)
{
for(j = 0; j < n-k; j++)
{
if(*(p+j) > *(p+j+1))
{
temp = *(p+j);
*(p+j) = *(p+j+1);
*(p+j+1) = temp;
}
}
}
}
void out_(int *p, int n)
{
int i =0;
for(i = 0; i < n; i++ )
{
printf("%d-4d\n", *(p+i));
}
}
void myFree(int *ptr)
{
free(ptr);
ptr = NULL;
}
/*
int m;
int n = 520;
static int k;
static int l = 666;
char arr[10] = "hello world";//arr数组在全局区的.data,而"hello world"在ro段
char *p = "hello"; //指针在.data段,而"hello"在.ro段
void swap(int m, int n)
{
int temp;
temp = m;
m = n;
n = temp;
printf("m = %d, n = %d\n", m, n);
}
void fun(int *p, int *q)
{
int *temp = 0;
temp = p;
p = q;
q = temp;
printf("*p = %d, *q = %d\n", *p, *q);
}
void gun(int *p, int *q)
{
int temp;
temp = *p;
*p = *q;
*q = temp;
printf("*p = %d, *q = %d\n", *p, *q);
}
int *iun()
{
static int value = 999;
return &value;
}
*/
int main(int argc, const char *argv[])
{
/*
double b = 999.0;
int a;
static int c;
static int d = 520;
char *p = "nihao";
char e[100] = "hello world";
int *ptr = (int *)malloc(sizeof(int));
int num = 520;
int key = 1314;
swap(num, key);
printf("调用后swap,主函数中num = %d, key = %d\n", num, key);
fun(&num, &key);
printf("调用后,主函数num = %d, key = %d\n", num, key);
gun(&num, &key);
printf("调用gun后, 主函数中num = %d, key = %d\n", num ,key);
int *ptr = iun();
*iun() = 555;
int *ptr1 = iun();
printf("*iun() = %d\n", *iun());
printf("*ptr = %d\n", *ptr);
printf("*ptr1 = %d\n", *ptr1);
*/
/*
int *p1 = (int *)malloc(4);
printf("*p1 = %d\n", *p1);
int *p2 = (int *)malloc(sizeof(int));
*p2 = 520;
printf("*p = %d\n", *p2);
int *p3 = (int *)malloc(sizeof(int)*5);
for(int i = 0; i < 5; i++)
{
printf("%p\n", (p3+i));
}
printf("\n");
//释放堆区空间
free(p1);
p1 = NULL;
free(p2);
p2 = NULL;
free(p3);
p3 = NULL;
*/
int *p1 = fun(6);
intput(p1,6);
sort_(p1,6);
out_(p1, 6);
myFree(p1);
p1 = NULL;
return 0;
}