#include
#include
#include
typedef int bool;
#define true 1
#define false 0
struct Arr{
int* pBase;
int len;
int cent;
};
bool append_arr(struct Arr* pArr,int val);
bool is_Full(struct Arr* pArr);
void init_rr(struct Arr* array,int length);
void show(struct Arr* pArr);
bool is_Empty(struct Arr* pArr);
int main(void){
struct Arr arr;
init_rr(&arr,5);
show(&arr);
append_arr(&arr,2);
append_arr(&arr,3);
append_arr(&arr,4);
append_arr(&arr,5);
append_arr(&arr,6);
show(&arr);
return 0;
}
//初始化;
void init_rr(struct Arr* array,int length){
array->pBase = (int*)malloc(sizeof(int)*length);
if(array->pBase = NULL){
printf("动态内存分配失败");
}
else{
array->len = length;
array->cent = 0;
}
}
//判断是否为空;
bool is_Empty(struct Arr* pArr){
if(pArr->cent == 0){
return true;
}
else{
return false;
}
}
//输出数组;
void show(struct Arr* pArr){
if(is_Empty(pArr)){
printf("数组是空的\n");
}
else{
for(int i=0;icent;i++){
printf("%d ",*(pArr->pBase));
}
}
}
//追加数字;
bool append_arr(struct Arr* pArr,int a){
if(is_Full(pArr))
return false;
pArr->pBase[pArr->cent] = a;
(pArr->cent)++;
return true;
}
//判断是否为满;
bool is_Full(struct Arr* pArr){
if(pArr->cent == pArr->len){
return true;
}
else{
return false;
}
}
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define true 1
#define false 0
struct Arr{
int* pBase;
int len;
int cent;
};
bool append_arr(struct Arr* pArr,int val);
bool is_Full(struct Arr* pArr);
void init_rr(struct Arr* array,int length);
void show(struct Arr* pArr);
bool is_Empty(struct Arr* pArr);
int main(void){
struct Arr arr;
init_rr(&arr,5);
show(&arr);
append_arr(&arr,2);
append_arr(&arr,3);
append_arr(&arr,4);
append_arr(&arr,5);
append_arr(&arr,6);
show(&arr);
return 0;
}
//初始化;
void init_rr(struct Arr* array,int length){
array->pBase = (int*)malloc(sizeof(int)*length);
if(array->pBase == NULL){
printf("动态内存分配失败");
}
else{
array->len = length;
array->cent = 0;
}
}
//判断是否为空;
bool is_Empty(struct Arr* pArr){
if(pArr->cent == 0){
return true;
}
else{
return false;
}
}
//输出数组;
void show(struct Arr* pArr){
if(is_Empty(pArr)){
printf("数组是空的\n");
}
else{
for(int i=0;i<pArr->cent;i++){
printf("%d ",*(pArr->pBase + i));
}
}
}
//追加数字;
bool append_arr(struct Arr* pArr,int a){
if(is_Full(pArr))
return false;
else{
pArr->pBase[pArr->cent] = a;
(pArr->cent)++;
return true;
}
}
//判断是否为满;
bool is_Full(struct Arr* pArr){
if(pArr->cent == pArr->len)
return true;
else
return false;
}
38行改为
if(array->pBase == NULL)