为了账号安全,请及时绑定邮箱和手机立即绑定

C语言模拟数组时遇到的问题,编译无误,但无输出

C语言模拟数组时遇到的问题,编译无误,但无输出

轩莫 2019-07-25 08:42:12
# include <stdio.h># include <malloc.h>void inint(struct Arrylist *,int);//bool add(struct Arrylist *, int, int);//bool del(struct Arrylist *, int, int);bool reverse(struct Arrylist *);bool show(struct Arrylist *);//bool is_empty(struct Arrylist *);//bool is_full(struct Arrylist *);//bool append(struct Arrylist *, int);struct Arrylist{ int * p;//the address of the first element of the arrylist int con;//the real element number of the arrylist int len;//the max of the length of the arrylist};int main(void){ struct Arrylist * ay; inint(ay, 6); append(ay, 1); append(ay, 2); append(ay, 3); show(ay); return 0;}bool is_full(struct Arrylist * arry)//judge a arry is full or not{ if(arry->con == arry->len) { return true; } else { return false; }}bool show(struct Arrylist * arry)// to show the arry{ if( is_empty(arry) ) { printf("The arrylist is empty!\n"); return false; } for(int i = 0; i < arry->con-1; i++) { printf("show the arry :%d", (arry->p)[i]); } return true;}void inint(struct Arrylist * arry, int len)//inintilization the arry{ arry->p = (int *)malloc(sizeof(int)*len); arry->con = 0; arry->len=len; return;}bool append(struct Arrylist * arry, int val){ if( is_full(arry) ) { printf("the arry is full!\n"); return false; } arry->p[arry->con-1] = val; arry->con++; return true;}bool is_empty(struct Arrylist * arry)//judege whether a arry is empty or not{ if(arry->con == 0) { return true; } else { return false; }}bool add(struct Arrylist * arry, int pos, int val)//add element{ if(is_full(arry)) { printf("Arrylist is full!"); return false;  } else if(pos < 1 || pos > arry->con+1) { printf("Wrong add!"); return false; } else { for(int i = arry->con; i > pos; i--) { (arry->p)[i-1] = (arry->p)[i-2]; } (arry->p)[pos-1] = val; arry->con++; return true; }}
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 1003 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信