• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

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

# include
# include


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));
        }
        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;


        }




}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!