algorithm_two_five.cpp

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

CPP
41
字号
#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));
  if(L.elem==NULL) return 0;
  L.Lenth=10;
  return 1;
}

char ListDelete(Sqlist &L,int i)
{
Elemtype *P,*Q;
if (i<0||i>L.Lenth-1) return 0;
P=L.elem+L.Lenth-1;//要引用数据结构中的变量时必须通过结构体对象明
Q=&L.elem[i];
for(;Q<=P-1;Q++)*Q=*(Q+1);
L.Lenth--;
return 1;
}


void main()
{
  Sqlist K;
  InitList(K);
  ListDelete(K,2);
  printf("%d",K.Lenth);


}

⌨️ 快捷键说明

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