arithtic_two_four.cpp

来自「数据结构的的源码」· C++ 代码 · 共 38 行

CPP
38
字号
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define Elemtype int

typedef struct{
	Elemtype *elem;
    int Lenth;
}Sqlist;

char InitList(Sqlist &L)
{
  L.elem=(Elemtype *)malloc(11*sizeof(Elemtype));//切忌在分配内存时应当用SIZEOF 计算单元值
  if (L.elem==NULL) return 0;
  L.Lenth=10;
  return 1;
}


char  ListInsert(Sqlist &L,Elemtype B,int i)
{
 Elemtype *P,*Q;
 if(i<1||i>=L.Lenth)return 0;
 P=&L.elem[i-1];
 for(Q=&(L.elem[L.Lenth-1]);Q>=P;Q--)*(Q+1)=*Q;
    *P=B;
	L.Lenth++;
	return 1;
}

void main()
{
Sqlist K;
InitList(K);
ListInsert(K,5,2);
printf("%d",K.elem[1]);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?