天谕玲珑动作怎么操作 天谕玲珑动作模式攻略推荐

亲爱的马可波罗 亲爱的马可波罗
回答
  • Nichkhin Nichkhin

    展开全部#include
    include
    include
    defineoverflow-2
    define ok 1
    define error 0
    definel**t_init_size 100
    definel**tincrement 10
    typedef intelemtype;typedef intstatus;定义顺序存储结构
    typedef struct
    {
    elemtype*elem;int length;int l**tsize;}sql**t;初始化顺序表
    statusinitl**t_sq(sql**t&l)
    {
    l.elem=(elemtype*)malloc(l**t_init_size*sizeof(elemtype));if!l.elem)exit(error);l.length=0;l.l**tsize=l**t_init_size;return ok;}
    自定义创建顺序表
    voidcreate_sql**t(sql**t&l)
    {
    int c,i=0;int*newbase;printf("请输入顺序表元素:\n");while((scanf("%d",&c))!eof)
    {
    if(i>=l.l**tsize)/自定义顺序表大小超过初始化大小
    {
    newbase=(elemtype*)realloc(l.elem,(l.l**tsize+l**tincrement)*sizeof(elemtype));为初始顺序表以l**tincrement大小重新增加存储空间
    if!newbase)exit(overflow);l.elem=newbase;l.l**tsize+l**tincrement;}
    l.elem[i+]=c;}
    l.length=i;printf("输入的顺序表元素:\n");for(i=0;i;i+)
    printf("%d",l.elem[i]);printf("\n");}
    在指定位置插入元素
    statusl**tinsert(sql**t&l,int i,elemtype e)
    {
    elemtype*p,*q,*newbase;if(i|i>l.length+1)
    {
    printf("插入位置错误\n");return(error);}
    if(l.length>=l.l**tsize)
    {
    newbase=(elemtype*)realloc(l.elem,(l.l**tsize+l**tincrement)*sizeof(elemtype));if!newbase)exit(overflow);l.elem=newbase;l.l**tsize+l**tincrement;}
    if(i=l.length)l.elem[i+1]=e;q=(l.elem[i-1]);for(p=(l.elem[l.length-1]);p>=q;p)*(p+1)=*p;q=e;l.length;return ok;}
    在指定位置删除元素
    statusl**tdelete_sq(sql**t&l,int i,elemtype*e)
    {
    elemtype*p,*q;if(i|i>l.length+1)
    return error;p=(l.elem[i-1]);e=*p;q=l.elem+l.length-1;for(+p;p;p)
    (p-1)=*p;l.length;return ok;}
    void main()
    {
    sql**t l;int m,n;int location,element;if!initl**t_sq(l))
    {
    printf("初始化顺序表失败!\n");exit(error);}
    create_sql**t(l);for(m=0;m;m+)
    {
    printf("输入插入位置:");scanf("%d",&location);while(location>l.length+1|location)
    {
    printf("输入位置错误,请重新输入!\n");scanf("%d",&location);}
    printf("插入元素:");scanf("%d",&element);if!l**tinsert(l,location,element))
    {
    printf("顺序表插入失败!\n");exit(error);}
    printf("插入顺序表为:\n");for(int i=0;i;i+)
    {
    printf("%d",l.elem[i]);}
    printf("\n新顺序表一共有%d个元素。\n",l.length);}
    for(n=0;n;n+)
    {
    printf("输入删除位置:");scanf("%d",&location);while(location>l.length|location)
    {
    printf("输入位置错误,请重新输入!\n");scanf("%d",&location);}
    if!l**tdelete_sq(l,location,&element))
    {
    printf("删除错误!\n");exit(error);}
    printf("被删除的元素为:%d \n",element);printf("被删除后的顺序表为:\n");for(int j=0;j;j+)
    {
    printf("%d",l.elem[j]);}
    printf("\n新顺序表一共有%d个元素。\n",l.length);}
    }
    这个是我最近编写的 顺序表也是线性表的
    这里还有链表的程序 用的话再传给你

类似问答
精品推荐

友情链接

友链互换QQ:

谷财 备案编号:蜀ICP备11019336号-3商务合作:235-677-2621

Copyright 2009-2020 Chengdu Sanzilewan Technology Co.,Ltd all rights reserve

抵制不良游戏 拒绝盗版游戏 注意自我保护 谨防受骗上当 适度游戏益脑 沉迷游戏伤身 合理安排时间 享受健康生活