zoukankan      html  css  js  c++  java
  • 3.顺序表的删除运算

     1 
     2 #include <stdio.h>
     3 #include <stdlib.h>
     4 #include <malloc.h>
     5 
     6 #define OK   1
     7 #define ERROR  0
     8 #define TRUE 1
     9 #define FALSE 0
    10 
    11 #define ElemType int
    12 #define    MAXSIZE  100      /*此处的宏定义常量表示线性表可能达到的最大长度*/
    13 typedef  struct
    14 
    15     ElemType  elem[MAXSIZE];   /*线性表占用的数组空间*/
    16     int  last;        /*记录线性表中最后一个元素在数组elem[ ]中的位置(下标值),空表置为-1*/
    17 }SeqList;
    18 
    19 int  DelList(SeqList *L,int i,ElemType *e)   /*在顺序表L中删除第i个数据元素,并用指针参数e返回其值。i的合法取值为1≤i≤L.last+1 */    
    20 
    21     int k;
    22     if((i<1)||(i>L->last+1))   
    23     { 
    24         printf("delect a error place!");
    25         return(ERROR);
    26     }
    27     *= L->elem[i-1];                 /* 将删除的元素存放到e所指向的变量中*/
    28     for(k=i; i<=L->last; k++)
    29         L->elem[k-1= L->elem[k]; /*将后面的元素依次前移*/
    30     L->last--;
    31     return(OK);
    32 }
    33 
    34 void main()
    35 {    
    36     SeqList *l;
    37     int p,r;
    38     int *q;
    39     int i;
    40     l = (SeqList*)malloc(sizeof(SeqList));
    41     q = (int*)malloc(sizeof(int));
    42      printf("please enter the length of stack:");
    43 
    44     scanf("%d",&r);
    45     l->last = r-1;
    46     printf("please insert the menbers of the stack:\n");
    47 
    48     for(i=0; i<=l->last; i++)
    49     {
    50         scanf("%d",&l->elem[i]);
    51     }
    52     printf("please input the place of number which you want to delect :\n");
    53 
    54     scanf("%d",&p);
    55     DelList(l,p,q);
    56     printf("the stack was delected is :%d",*q);
    57         printf("删除的元素值为:%d\n",*q);
    58 }
    59 
  • 相关阅读:
    ubuntu远程windows桌面
    spring boot 给返回值加状态 BaseData
    spring boot 拦截异常 统一处理
    IntelliJ IDEA spring boot 远程Ddbug调试
    IntelliJ IDEA 常用插件
    spring boot 请求地址带有.json 兼容处理
    spring boot 接口返回值去掉为null的字段
    spring boot 集成disconf
    Spring boot 自定义拦截器
    Linux下安装MySQL
  • 原文地址:https://www.cnblogs.com/zhangqs008/p/1523737.html
Copyright © 2011-2022 走看看