vp2吧 关注:0贴子:24
  • 2回复贴,共1

第二名哈哈。

只看楼主收藏回复



回复
来自iPhone客户端1楼2015-09-17 19:54


    回复
    来自Android客户端2楼2015-09-17 22:19
      /* Note:Your choice is C IDE */
      #include "stdio.h"
      #include<stdio.h>
      #include<stdlib.h>
      #define LIST_INIT_SIZE 100
      #define LISTINCREMENT 10
      typedef struct


      { int *base; int length;
      int listsize; }Sqlist;
      Sqlist InitList_Sq()
      { Sqlist L;
      L.base=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
      if(!L.base)
      { printf("初始化失败!");
      exit(0); } L.length=0;
      L.listsize=LIST_INIT_SIZE; return L; }
      void write(Sqlist *L,int elem)
      { if(L->length<L->listsize)
      { L->base[L->length++]=elem;
      } else
      { printf("存储已满!");
      exit(0); } }
      void Insert_Sq(Sqlist *L,int position,int element)
      { int *p,*q; if(position<1||position>L->length+1)
      { printf("插入位置非法!"); exit(0); }
      if(L->length>=L->listsize)
      { int *newbase=(int *)realloc(L->base,(L->listsize+LISTINCREMENT)*sizeof(int));
      if(!newbase) exit(0); L->base=newbase;
      L->listsize+=LISTINCREMENT; } q=&(L->base[position-1]);
      for(p=&(L->base[L->length-1]);p>=q;--p) { *(p+1)=*p; } *q=element; L->length++; }


      void delete_Sq(Sqlist *L,int position)
      { int i=0; if(position<1||position>L->length)
      { printf("非法操作!"); exit(0); }
      printf("成功删除base[%d]=%d",position,L->base[position]);
      for(i=position;i<L->length-1;i++)
      {L->base[i]=L->base[i+1]; } L->length--; }


      int getElem(Sqlist *L,int position)
      { return L->base[position-1]; }


      void showData(Sqlist *L)
      { int i=0; for(i=0;i<L->length;i++)
      { if(i%5==0) printf("\n");
      printf("%d ",L->base[i]); }
      printf("\n"); }
      void main()
      { int i=0,a,b; Sqlist list,*l;
      list=InitList_Sq(); l=&list;
      for(i=0;i<list.listsize/5;i++)
      { write(l,i+1); }
      a=getElem(l,8); b=getElem(l,13);
      printf("base[8]=%d,base[13]=%d",a,b);
      showData(l);
      printf("length=%d,listsize=%d\n",list.length,list.listsize);
      Insert_Sq(l,7,3);
      showData(l);
      printf("length=%d,listsize=%d\n",list.length,list.listsize); }


      回复
      3楼2015-10-27 11:17